eygraber / JsonPathKt

A lighter and more efficient implementation of JsonPath in Kotlin Multiplatform
BSD 3-Clause "New" or "Revised" License
39 stars 2 forks source link

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

Closed tlevavasseur-decathlon closed 3 weeks ago

tlevavasseur-decathlon commented 2 months ago

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

eygraber commented 2 months ago

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 commented 2 months ago

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

tlevavasseur-decathlon commented 2 months ago

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

eygraber commented 2 months ago

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

SettingDust commented 2 months ago

图片

The result is the first and the last in spec 0.8.3