Using jsonpath to get parent node

爷,独闯天下 提交于 2019-12-01 20:33:54

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.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!