I have a json array which im getting my react data from it, the json is like this:
JavaScript
x
16
16
1
{
2
"Folders": [
3
{
4
"name": "parent 2",
5
"children": [ //this is children_1
6
{
7
"name": "parent 2",
8
"id": "parent 2",
9
"children": [] //this is children_2
10
}
11
],
12
"id": 1
13
}
14
]
15
}
16
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 ?
Advertisement
Answer
Look at jsonpath
so it will be
JavaScript
1
4
1
var json = require('jsonpath');
2
var names = jp.query(json, '$.Folders[*].children[*].children');
3
4