draft-ietf-jsonpath-base icon indicating copy to clipboard operation
draft-ietf-jsonpath-base copied to clipboard

Syntax for returning a set of indices/keys of an array/object

Open gregsdennis opened this issue 1 year ago • 19 comments

This question popped up on StackOverflow in which the user wants to select the keys present in the resulting object. To do this, they're expecting to end the query with ~.

So $.*~ would select all of the items and then return the keys for those items.

In a more complex query, you could have $[[email protected] == 5]~ to find the property names (or array indices) of every child that meets the condition.

To date, I've asked what implementation they're using that supports this syntax, but I've yet to receive a result.

We also have #324 that proposed a function extension to do this rather than syntax, but there wasn't much discussion there other than the data is available through the location paths in the query result. The problem with this is that you can't check that until the query is complete.

I think a benefit of this is that you could continue querying on the property name set.

Building on the more complex example, with an array of objects, if I wanted the index of the third item where @.foo == 5, I could do $[[email protected] == 5]~[2].

Logging for visibility and discussion. It seems simple enough. (This would also be the first functionality that actually uses the location data as part of the query.)

gregsdennis avatar Feb 21 '24 00:02 gregsdennis