How To Find Parentnode From Childnode In A Json Structure Using Jsonpath Or An Alternative?
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
Solution 1:
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:
- Adding a property "parent_id" to every node in the JSON, query the JSON using jsonPath.
Solution B:
- Not using jsonPath for this task and instead keeping an in memory rap-presentation of the JSON as a "flat" array, when populating the array I can add to each node a "parent_id" as to find a child node I always need to know its parent (as suggested from comments). Any search is done on the "flat" array using JS.
Post a Comment for "How To Find Parentnode From Childnode In A Json Structure Using Jsonpath Or An Alternative?"