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 Tilde #69

Open
omid opened this issue Jun 15, 2021 · 5 comments
Open

Support Tilde #69

omid opened this issue Jun 15, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@omid
Copy link

omid commented Jun 15, 2021

I would like to get the keys of the matching objects.
For example, when I have the following JSON:

{
   "a": {
       "check": true
   },
   "b": {
       "check": true
   },
   "c": {
       "check": false
   }
}

I want to get ["a","b"] with the following selector: $[?(@.check==true)]~

I know it's Jsonpath-Plus. But does this library support it? Is there any plan to go that way? Is there any way I achieve my goal with the current code?

@freestrings freestrings added the enhancement New feature or request label Jun 20, 2021
@cburgmer
Copy link

It seems the ~ operator is meant to select part of the path and not a value from the JSON document.
I remember a discussion a while back with some of the people who are interested in identifying a standard around JSONPath where we mostly were in favour of sticking to the value aspect of JSONPath and not getting into the more complex transformation aspect.
Having said that, most libraries that implement JSONPath also return the list of paths that lead to the selected values.

@oshadmi
Copy link

oshadmi commented Aug 30, 2021

@cburgmer

Having said that, most libraries that implement JSONPath also return the list of paths that lead to the selected values.

Such as this?

args.resultType ("VALUE"|"PATH"):
    causes the result to be either matching values (default) or normalized path expressions.

For controlling the result type, could also consider inline/embedded flags (as regular expression inline flags, such as (?s) or (?i)), which doesn't require API changes and, in addition, some users may find more comfortable than adding arguments, although it could slightly cost in performance.

When path includes wildcard, union, recursive descent or slice, the need for getting the concrete paths seems even more justified.

@cburgmer
Copy link

Having said that, most libraries that implement JSONPath also return the list of paths that lead to the selected values.

Such as this?

args.resultType ("VALUE"|"PATH"):
    causes the result to be either matching values (default) or normalized path expressions.

Exactly.
For example, I implemented this in Clojure: https://github.com/gga/json-path#usage (compare json-path/at-path to json-path/query).

For controlling the result type, could also consider inline/embedded flags (as regular expression inline flags, such as (?s) or (?i)), which doesn't require API changes and, in addition, some users may find more comfortable than adding arguments, although it could slightly cost in performance.

I am not sure I fully understand, but it seems you are arguing for extending the JSONPath syntax to include a query to extract the path, whereas how I understand Goessner and also have seen this in other implementations, you would instead call just a different API.

When path includes wildcard, union, recursive descent or slice, the need for getting the concrete paths seems even more justified.

Agreed.

@emmanuelkeller
Copy link

Adding reference regarding the nodes library jsonpath-plus
This library introduces two operators:

  • ^ for grabbing the parent of a matching item
  • ~ for grabbing property names of matching items (as array)

This can be tested online with this JSON path evaluator.
If you use the following JSON path: $.address.*~, you will get an extraction of the keys:

[
  "streetAddress",
  "city",
  "postalCode"
]

@deitmerit
Copy link

deitmerit commented Nov 7, 2021

Adding reference regarding the nodes library jsonpath-plus This library introduces two operators:

  • ^ for grabbing the parent of a matching item
  • ~ for grabbing property names of matching items (as array)

This can be tested online with this JSON path evaluator. If you use the following JSON path: $.address.*~, you will get an extraction of the keys:

[
  "streetAddress",
  "city",
  "postalCode"
]

Notice that with version 0.3.0, you get the values instead (try here):

[
  "naist street",
  "Nara",
  "630-0192"
]

I would consider this a bug.

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

No branches or pull requests

6 participants