question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to extract values from nested json objects using JSON Extractor

See original GitHub issue

I have a json file that contains a few properties, say,

{
  "A": [
    {
      "property1": "value 1",
    },
    {
      "A1": [
        {
          "property2": "value 2",
          "property3": "value 3"
        }
      ],
      "property4": "value 4"
    }
  ],
  "B": {
     "custom": {
      "B1": [
        {
           "property5": "value 5",
           "property6": "value 6",
           "property7": "value 7"
        }        
      ],
      "metrics": [ ]
    },
    "property8": { }
  }
}

Few of them are nested. How to extract the nested property values using JSON extractor. For example, I want to extract the values of properties 5,6,7.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rukmanigcommented, May 17, 2016

Hi, you can use the JsonTuple function to get the values, the code snippet to extract the properties 5,6 and 7 is done as follows

@jsonnodes = SELECT JsonApp.JsonFunctions.JsonTuple(jsonstring, “$…property5”, “$…property6”, “$…property7”) AS json_map FROM @json;

@nodes_exploded = SELECT name, node_value FROM @jsonnodes CROSS APPLY EXPLODE(json_map) AS T(name, node_value);

The snippet above will give you an output as follows “custom.B1[0].property5”, “value 5” “custom.B1[0].property6” , “value 6” “custom.B1[0].property7”, “value 7”

Please let me know if this helps and if you have any further questions.

1reaction
rukmanigcommented, Jun 3, 2016

jsonstring is the string you extracted out of the JSON using the JSONExtractor. I have also published code that parses Json on the github site - please do take a look at https://github.com/Azure/usql/blob/master/Examples/JsonSample/JsonSample/NestedJsonParsing.usql that will give the full script that starts with extracting content from a JSON file and manipulating the data. Please let me know if you have any questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to extract nested elements in JSON response using ...
I would like to extract an element based on a condition inside a nested JSON response. Using the widely searched example below, ...
Read more >
How to unnest / extract nested JSON data in MySQL 8.0
For simple JSON strings like these, we just need to use the JSON_EXTRACT() function.
Read more >
Extract data from nested json array / meta_data
Hi guys,. i have got the below Json result, and i want to extract order_no and deliverydate for each order using power automate....
Read more >
How to extract nested JSON fields and array from S...
I'm trying to extract some information from nested JSON data stored in Splunk. Here's a simplified and anonymized example of the type of ......
Read more >
Extract Nested Data From Complex JSON
Extract Nested Data From Complex JSON. Never manually walk through complex JSON objects again by using this function. Todd Birchard · Python.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found