Skip to content

Support for results as path #5

Description

@jcoyne

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions