Using jsonpath to get parent node

后端 未结 2 1159
日久生厌
日久生厌 2021-01-14 18:28

Using node JSONPath, how can I get the parent node name from child node value

相关标签:
2条回答
  • 2021-01-14 19:01

    Unfortunately, JSONpath does not support search by parameters in the contents of a child object: http://goessner.net/articles/JsonPath/

    0 讨论(0)
  • 2021-01-14 19:06

    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.

    0 讨论(0)
提交回复
热议问题