1

I am fairly new with Jsonpath and am forced to use due to a project dependency.

The sample json loooks like this

{
  "people": {
    "a": {"First":"James", "last": "d"},
    "b": {"First":"Jacob", "last": "e"},
    "c": {"First":"Jayden", "last": "f"},
    "d": {"First":"different", "last" : "g"}
  }
}

I am intending to get the last value where First value starts with "J".

So Intended output is

 "d","e","f"

The same thing can be achieved with jq using

'.people | .[] | select (.First | startswith("J")) | .last'

However , after having referring multiple online tutorials , I am unable to get a hang of how piped filters work with jsonpath and how the above result can be achieved. The nearest I could reach with the expression was :

"people.*[?starts_with(arn,`J`)].last"

But it doesn't yield any output.

It would be great if someone can point me towards any article that can help me solve this issue or understand the querying structure of jsonpath.

Thanks alot.

ram
  • 11

1 Answers1

0

The solution is to use function values(@). Got the reference from

https://github.com/jmespath/jmespath.site/issues/24

So one of the possible solution for above question is

people.values(@)[?starts_with(First,`J`)].last
ram
  • 11