Get a list of values in a JSON object with jq
The equivalent to Python’s dict.values()
is jq '[.[]]'
.
Here’s an example:
$ echo '{"1": ["one", "uno", "eins"], "2": ["two", "dos", "zwei"], "3": ["three", "tres", "drei"]}' > numbers.json
$ jq -c '[.[]]' numbers.json
[["one","uno","eins"],["two","dos","zwei"],["three","tres","drei"]]
How it works:
.[]
is the object value iterator, which returns all the values of an object.$ jq -c '.[]' numbers.json ["one","uno","eins"] ["two","dos","zwei"] ["three","tres","drei"]
[]
constructs an array from whatever is passed in.