Skip to content

Support filter expressions with JSON.ARRINDEX <key> <path> [<json-scalar> | <json-filter>]] [start [stop]] #460

Open

Description

@mseada94

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.ARRINDEX store $.books '?(@.price < 10)'

Activity

  1. changed the title [-]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]]`[/+] on Sep 27, 2021
  2. changed the title [-]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]]`[/+] on Sep 27, 2021
  3. oshadmi commented on Oct 3, 2021

    @oshadmi
    Collaborator

    @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)

  4. mseada94 commented on Oct 3, 2021

    @mseada94
    Author

    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.

  5. Jeevananthan-23 commented on Dec 12, 2022

    @Jeevananthan-23

    JSON.ARRINDEX throws WRONGTYPE wrong type of path value - expected scalar but found { "City": "Chennai", "State": "TN" }
    image

  6. oshadmi commented on Dec 13, 2022

    @oshadmi
    Collaborator

    @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.

  7. self-assigned this
    on Dec 14, 2022
  8. added
    API
    and removed
    API
    on Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions