jmespath.py icon indicating copy to clipboard operation
jmespath.py copied to clipboard

Does jmespath support random selecting?

Open oylbin opened this issue 4 years ago • 1 comments

example data:

{
    "stores":{
        "s1":{
            "id":"s1",
            "openTime": 1234567890
        },
        "s2":{
            "id":"s2",
            "openTime": 1234567891
        },
        "s3":{
            "id":"s3",
            "openTime": 1234567892
        },
        "s4":{
            "id":"s4",
            "openTime": 1234567893
        }
    }
 }

I can get 'id's with

stores.*.id

I can get first id with

stores.*.id | [0]

Is there any build in function that let me random select an id from 'id's ? something like jinja2 random filter:

stores.*.id | random

oylbin avatar Aug 25 '20 02:08 oylbin

I think you can do something like this: 'stories.*id | [' + str(random.randint(0,3)) +']'

2kjiejie avatar Jul 17 '21 09:07 2kjiejie