-
Notifications
You must be signed in to change notification settings - Fork 20
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
Proposal - Selecting a subset of an object's properties #49
Comments
I like to thing of there being at least two different problems many people try solving in this space: That of selecting values, and that of transforming the original JSON structure. I understand JSONPath to solve the former, but to be really bad at the latter (by choice). |
@cburgmer what's the support for something like |
fwiw I'm also in the camp of "jsonpath selects and doesn't transform" |
I'm talking about the union operator with two keys: https://cburgmer.github.io/json-path-comparison/results/union_with_keys.html. You will get the values, but not the keys. Java's com.jayway.jsonpath interestingly enough decides to return the object with the keys, contrary to the rest of the implementations (and Objective-C's SMJJSONPath which according to it's goal just follows com.jayway.jsonpath verbatim). |
For further reference, Ruby's jsonpath has a "parens notation" (https://cburgmer.github.io/json-path-comparison/results/parens_notation.html) to select a subset: |
Interesting proposal regarding the syntax. I am also in the camp of "jsonpath selects and doesn't transform" (I've even been the first one :) The example above could be rewritten to [ "$['store']['book'][0]",
"$['store']['book'][1]",
"$['store']['book'][2]",
"$['store']['book'][3]"
] that can be used then to do any post-processing ... here transform to property-reduced books. No violation of the minimalism priciple this way! Proposed syntax |
See resolution of #109 at IETF 112. |
There's no syntax for selecting multiple individual properties from a single object. You either have to select a single property or the entire object.
I would like to propose a "union" or "subselection" syntax
(x,y,...)
wherex
, etc. are the properties to be returned. The return value will be an object omitting all properties that are not included in the union declaration.Using Goessner's example, I could use the path
$.store.book[*].(title,price)
to select only the title and price of all of the books. It would return*NOTE I understand the name conflicts with current usage of "union", but that be resolved by changing that usage. I'm struggling to come up with another name.
The text was updated successfully, but these errors were encountered: