Reputation: 74008
I need to find out a parentNode from childNode in a JSON structure. For example I need to know what is the parent for "view_id": "f"
.
I am evaluating jsonPath but I cannot find a parent operator.
I would like to now:
You can test JSON structure here: http://jsonpath.curiousconcept.com/
[
{
"view_id": "a",
"views": [
{
"view_id": "b",
"views": [
{
"view_id": "c"
},
{
"view_id": "d"
}
]
},
{
"view_id": "e",
"views": [
{
"view_id": "f"
},
{
"view_id": "g"
}
]
},
{
"view_id": "h"
}
]
},
{
"view_id": "i",
"views": [
{
"view_id": "l",
"views": [
{
"view_id": "m",
"views": [
{
"view_id": "n"
},
{
"view_id": "o"
}
]
}
]
},
{
"view_id": "p"
}
]
},
{
"view_id": "q"
}
]
Upvotes: 1
Views: 5359
Reputation: 74008
I found two possible solutions to this specif problem as for my understanding jsonPath
does not allow me to find the parent
for a node:
Solution A:
Solution B:
Upvotes: 3