jsonpath
jsonpath copied to clipboard
wild card doesn't work in filter (script)
Hi Guys,
I am not sure if they should, but documentation directly doesn't explain this.
My Case: { "store": { "book": [ { "category": [ {"reference": "referenceV1"}, {"reference": "referenceV2"} ], "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": [ {"reference": "referenceV2"}, {"reference": "referenceV4"} ], "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": [ {"reference": "referenceV1"}, {"reference": "referenceV2"} ], "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": [ {"reference": "referenceV3"}, {"reference": "referenceV1"} ], "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } } I need all prices that category has reference == "referenceV2". const result = jp.query(json, "$..book[?(@.category[*].reference=='referenceV2')]"); -- cause an errorUnexpected token *.
Is this is expected behavior ? If yes what is suggested way to work with inner arrays? const result = jp.query(json, "$..book[?(@.forEach(function(element) { console.log(element);}))]"); won't produce any console output.
Thanks, Slava