Array slicing does not follow the syntax in https://goessner.net/articles/JsonPath/
Closed this issue · 4 comments
khairihafsham commented
Problem:
$..book[:2]
produces 3 elements, where according to https://goessner.net/articles/JsonPath/, it should produce 2 elements.
$..book[::2]
produces 2 elements and consistent with the documentation for this repo.
Is this expected?
Reproduction Steps:
require 'jsonpath'
json = <<-HERE_DOC
{"store":
{"bicycle":
{"price":19.95, "color":"red"},
"book":[
{"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
{"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
{"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
{"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
]
}
}
HERE_DOC
# should produce the first 2 elements, but got 3 instead
puts JsonPath.new('$..book[:2].price').on(json)```
Skarlso commented
Hi @khairihafsham. I'll take a look soonish.:)
khairihafsham commented
I've created a PR. Not sure if it is appropriate. But, please have a look and comment if I need to make improvements.
Skarlso commented
Cool, I'll take a look. Thanks!
Skarlso commented
Thank you for your contribution! :)