jslt icon indicating copy to clipboard operation
jslt copied to clipboard

Implement array traversal operator?

Open larsga opened this issue 3 years ago • 1 comments

In this stackoverflow question someone wants to extract from each object in an array a key from each element in an array inside the first object.

It ends up having to be implemented like this:

flatten([for (.) [for (.locations) .state]])

However, if we allowed path expressions to iterate over an array and access elements of the array, like jq does with .[] we could write the same thing as:

.[].locations.[].state

which I think is nicer and more natural.

I've been thinking about this extension almost since JSLT was created, but have been waiting for a concrete use-case. Now it seems there is one. Thoughts?

larsga avatar Mar 13 '21 12:03 larsga

Discussion #191 shows another example with a need for this operator.

larsga avatar May 06 '21 13:05 larsga