Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for results as path #5

Open
jcoyne opened this issue Apr 11, 2018 · 0 comments
Open

Support for results as path #5

jcoyne opened this issue Apr 11, 2018 · 0 comments

Comments

@jcoyne
Copy link
Contributor

jcoyne commented Apr 11, 2018

The javascript jsonPath tool can support results as values or paths:
So that when we're using the data:

{
  "phoneNumbers": [
    {
      "type"  : "iPhone",
      "number": "0123-4567-8888"
    },
    {
      "type"  : "home",
      "number": "0123-4567-8910"
    }
  ]
}

and you query:

jsonPath(o, "$.[*].type")

you get the expected results:

[
  "iPhone",
  "home"
]

If you run the very same query, with the path result type, you see where these results came from:

jsonPath(o, "$.[*].type", {resultType:"PATH"})
[
  "$['phoneNumbers'][0]['type']",
  "$['phoneNumbers'][1]['type']"
]

You can see this feature in action here: http://jsonpath.com/

I find that I am in need of this feature, because I often want to do "give me the parents of the children that match this expression", which is something XPath can do, but JSONPath does not. Getting the paths is an easy way to work around a shortcoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant