Get the key values using jq from json Get the key values using jq from json elasticsearch elasticsearch

Get the key values using jq from json


It's best to avoid grep in cases like this. To meet the exact requirements in the present case, one could write:

jq -c 'paths(scalars) as $p| [$p, getpath($p)]| select(.[1] == "9i6O4ERWWB")' input.json

If one really needs grep-like functionality, you can always use jq's test/1.


You can 'extract' paths using the following:

jq -c 'paths(scalars) as $p | [$p, getpath($p)]' file.json | grep 432432sdxWWB

and response is:

[["_source","statistics","example.com","template2","subdomain_id"],"432432sdxWWB"]

Possibly you can improve jq query to get only single value but I hope it helps you in determining final version :)