Open mseada94 opened 3 years ago
@mohamed-seada-1994 You can use filter in the json path, e.g.,
json.set store $ '{"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95,"size":[10,20,30,40]},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99,"size":[50,60,70,80]},{"category":"fiction","author":"Herman Melville","title":"Moby Dick","isbn":"0-553-21311-3","price":8.99,"size":[5,10,20,30]},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99,"size":[5,6,7,8]}],"bicycle":{"color":"red","price":19.95}}}'
OK
json.get store '$.store.book[*].size'
"[[10,20,30,40],[50,60,70,80],[5,10,20,30],[5,6,7,8]]"
json.get store '$.store.book[?(@.price<10)].size'
"[[10,20,30,40],[5,10,20,30]]"
I will create an issue for json.arrindex
not returning indices from multiple arrays (only returning index from the first array)
json.arrindex store '$.store.book[?(@.price<10)].size' 20
(integer) 1
Will this resolve this issue? (#460)
I want to use json.arrindex
to get indices for all filtered items using JSON Path without specifying a scaler value.
Example: Get indices of all books with price < 10, I don't want to filter based on scaler value like the size property.
JSON.ARRINDEX
throws WRONGTYPE wrong type of path value - expected scalar but found { "City": "Chennai", "State": "TN" }
@Jeevananthan-23 Currently this command supports only scalar values. Please open another issue if you require to find by composite values, and also please mind that it may raise questions such as whether the comparison of composite values is partial or complete.
Currently you can use a filter with multiple conditions (using &&
) to return only matching objects.
@nermiller Although the error message seems clear, the documentation on JSON.ARRINDEX
is not clear enough and should mention that the value
argument must be a scalar.
Feature Request Please consider support the following command
JSON.ARRINDEX <key> <path> [<json-scalar> | <json-filter>]] [start [stop]] [S | F]
to return items index based on advanced filter expressions like $.books[?(@.price < 10)] Usage Example