jmespath.site icon indicating copy to clipboard operation
jmespath.site copied to clipboard

Should it be explained more thoroughly that a a function returns a projection?

Open b-enoit-be opened this issue 2 years ago • 1 comments

Let's say we have a list of list and want to select the sublist where a string starts with a letter.

So, given the JSON

[
    [
        "ab",
        "cd"
    ],
    [
        "ef",
        "gh"
    ]
]

One could do:

[?contains([].starts_with(@, `a`), `true`)]

But, in order to have a consistent notation, I was trying to make the contains function a dot notation too, so:

[?[].starts_with(@, `a`).contains(@, `true`)]

which does not work.

I figured out it as because starts_with returns a projection, so it can be achieved resetting it:

[?[].starts_with(@, `a`) | contains(@, `true`)]

But I feel, for a new comer that does not know that well about projections and resetting them, it should be explained in the specification in more details, shouldn't it?

b-enoit-be avatar Sep 03 '22 12:09 b-enoit-be

Yes, it definitely should be explained better.

springcomp avatar Oct 20 '22 21:10 springcomp