subscript on filtered set
Closed this issue · 5 comments
Hi, I was expecting to be able to subscript a filtered set, but get back an empty set. e.g.
$.store..books[?(@['category']=='fiction')].[0]
Maybe this is unsupported, maybe it's a bug, I don't know.
Below is a shell script where the first two paths return expected results, PATHEXP3
returns an empty set.
Any hints appreciated, thanks
PATHEXP1="$.store..books[?(@['category']=='fiction')]"
PATHEXP2="$.store..books[0]"
PATHEXP3="$.store..books[?(@['category']=='fiction')].[0]"
jsonpath $PATHEXP3 <<EOF
{ "store": [
{ "books": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
} ] },
{ "bicycles": [
{
"color": "red",
"price": 19.95
}
] }
] }
EOF
Hey!
Thanks for reporting. I'll take a look as soon as I can!
Can you try "$.store..books[?(@['category']=='fiction')][0]" instead of
"$.store..books[?(@['category']=='fiction')].[0]"`?
Yeah, it's not a thing that is supported. It's kind of like this thing: http://jsonpath.com/. And this kind of behaviour doesn't work with that either.
In code, it works of course, because it returns multiple elements. But it doesn't work with the CLI. :/ Sorry.