1
votes

I'm having this json:

{
  "paths": {
      "foo": {
          "key": 1
      },
      "bar": {
          "key": 2
      }
  }
}

I would like to use JSONPath to find element "foo" by its name ("foo")

I tried something like $.paths.*.[?(~=='foo')] but it does not seem to work (I checked on https://jsonpath.com)

1
Find element "foo" based on what? Its name? As the parent of "key: 1"? The first child of "paths"? - Jack Fleeting
by its name - "foo" - Tomasz Madeyski

1 Answers

1
votes

If you need the to find the element by its name, this expression

$.paths.foo

outputs

[
    {
        "key": 1
    }
]