You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support filter expressions with JSON.ARRINDEX <key> <path> [<json-scalar> | <json-filter>]] [start [stop]] #460
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
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
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.
@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.
Activity
[-]Support filter expressions with `JSON.ARRINDEX <key> <path> [<json-scalar> | FILTER <json-filter>]] [start [stop]][/-][+]Support filter expressions with `JSON.ARRINDEX <key> <path> [<json-scalar> | FILTER <json-filter>]] [start [stop]]`[/+][-]Support filter expressions with `JSON.ARRINDEX <key> <path> [<json-scalar> | FILTER <json-filter>]] [start [stop]]`[/-][+]Support filter expressions with `JSON.ARRINDEX <key> <path> [<json-scalar> | <json-filter>]] [start [stop]]`[/+]oshadmi commentedon Oct 3, 2021
@mohamed-seada-1994
You can use filter in the json path, e.g.,
I will create an issue for
json.arrindexnot returning indices from multiple arrays (only returning index from the first array)Will this resolve this issue? (#460)
mseada94 commentedon Oct 3, 2021
I want to use
json.arrindexto 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.
Jeevananthan-23 commentedon Dec 12, 2022
JSON.ARRINDEXthrowsWRONGTYPE wrong type of path value - expected scalar but found { "City": "Chennai", "State": "TN" }oshadmi commentedon Dec 13, 2022
@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.ARRINDEXis not clear enough and should mention that thevalueargument must be a scalar.