Using node JSONPath, how can I get the parent node name from child node value
Unfortunately, JSONpath does not support search by parameters in the contents of a child object: http://goessner.net/articles/JsonPath/
You do not specify which implementation of JSON Path, but with both Gatling (Scala) and JayWay (Java) you can use nested filters to filter by children while returning the parent, grandparent or whatever. Here is a sample:
With this JSON:
{
"a": {
"b": {
"c": {
"d": {
"e": "foo"
}
},
"something": "bar"
}
}
}
And this path:
$.a.b[?(@.c[?(@.d[?(@.e == "foo")])])].something
Returns:
[ "bar" ]
I am able to retrieve b
by using expressions to get to lower nodes as the filter.
Some other implementations error out on these expressions.