Home > Mobile >  Extracting a data from json array by certain key in java script
Extracting a data from json array by certain key in java script

Time:12-28

I have a json array which im getting my react data from it, the json is like this:

 {
         "Folders": [
           {
             "name": "parent 2",
             "children": [        //this is children_1
                {
                  "name": "parent 2",
                  "id": "parent 2",
                  "children": []     //this is children_2
                 }
               ],
               "id": 1
            }
          ]
        }

lets say i have the key value of name inside children(children_1) and i want to get the rest of the data inside that children using the name that i have, is there a way to do that ?

CodePudding user response:

Look at jsonpath

so it will be

var json = require('jsonpath');
var names = jp.query(json, '$.Folders[*].children[*].children');

  • Related