PaesslerAG / jsonpath

BSD 3-Clause "New" or "Revised" License
172 stars 37 forks source link

Is it possible to get the length of an array? #15

Closed steinfletcher closed 5 years ago

steinfletcher commented 5 years ago

Hi, thanks for this great library.

I was hoping to do something like this.

$.items.length or $.items.length(). I get the following errors.

could not select value, invalid key: expected number but got length (string)

Is there another way to get the length?

Thanks

generikvault commented 5 years ago

Hi, thanks.

Yes there isn't a length function. You can add one via gval.Function but this would be outside the jsonpath like length($.items).

Is that a solution for you?

steinfletcher commented 5 years ago

Thanks for the quick reply. Yes that sounds good. How does one define a gval.Function, I am not sure how that works?

generikvault commented 5 years ago

You can use this example https://godoc.org/github.com/PaesslerAG/gval#example-Language with Function instead of PostfixOperator. You can use any function signature.