JsonPathKt icon indicating copy to clipboard operation
JsonPathKt copied to clipboard

`$[0,-1:].name` returns the whole list

Open tlevavasseur-decathlon opened this issue 1 year ago • 5 comments

using the path $[0,-1:].name on

[
  { "name": "name1" },
  { "name": "name2" },
  { "name": "name3" },
  { "name": "name4" },
]

returns the 4 names.

Compared with an online evaluator which validates this syntax

tlevavasseur-decathlon avatar Jul 14 '24 16:07 tlevavasseur-decathlon

In this case we match the evaluator at https://jsonpath.curiousconcept.com/ where the first index is used, and any other indexes are ignored, and then the colon is interpreted as a range extending to the end of the array.

I'm not sure how we should actually handle it (either make it an error or ignore the trailing colon) because I don't think the existing behavior is the most intuitive. I need to think more on that.

eygraber avatar Jul 14 '24 22:07 eygraber

@tlevavasseur-decathlon what would you expect that path to do?

eygraber avatar Jul 15 '24 16:07 eygraber

Hi, I was expecting an array of $[0].name and $[-1:].name (which works with your lib) but I can do with this syntax $[0,-1].name (I hadn't tried this one until now). Thanks

tlevavasseur-decathlon avatar Jul 16 '24 06:07 tlevavasseur-decathlon

I'll update the library to reflect that, thanks for the report.

eygraber avatar Jul 16 '24 06:07 eygraber

图片

The result is the first and the last in spec 0.8.3

SettingDust avatar Jul 26 '24 23:07 SettingDust