-
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
ER - Provide syntax for returning a specific number of filtered elements #95
Comments
This could also be used in a form of pagination (offset/length), but that could be a local API and not a feature of JSONPath. |
I think having a syntax for it is valuable. Individual libraries implementing this independently doesn't serve uniformity. |
I agree such a feature has some value, but I'm not convinced it has enough value to warrant adding complexity to the spec. |
Fair enough. I think this should remain open and perhaps labeled as a |
112 output:
|
I actually had this requested recently in json-everything/json-everything#583. Basically they're doing a recursive descent, but they only want the first result. I ended up making my library return .net's deferred execution Linq queries, which allows them to tack on other .net functionality to make the query stop early rather than continue querying the entire document. It'd be really nice to have syntax to handle this. |
A gentleman by the username of gregsdennis on Stack Overflow suggested I raise this issue here for consideration into the specification:
https://stackoverflow.com/questions/67477431/json-path-is-there-a-way-to-only-return-a-specific-number-of-filtered-elements/67477600
Given an object like this:
{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } }
and running a JSON path expression like so:
$..book[?(@.price<10)]
Will return 2 objects:
[ { "category" : "reference", "author" : "Nigel Rees", "title" : "Sayings of the Century", "price" : 8.95 }, { "category" : "fiction", "author" : "Herman Melville", "title" : "Moby Dick", "isbn" : "0-553-21311-3", "price" : 8.99 } ]
it would be great if JSON Path also provide syntax for returning the first or last 'n' items of the filtered array
e.g. if I only wanted maximum 1 item from the result of the filtering operation:
$..book[?(@.price<10)]{1}
The text was updated successfully, but these errors were encountered: