I have this
{ "1": { "Split": { "result": "first_image" } }, "2": { "Split": { "result": "second_image" } } }
I tried .[].Split.result but it gives be below result;
“first_image”
“second_image”
but I want below output
I want the below output
[“first_image”,”second_image”]
user27354765 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Collect the results you get into an array by wrapping your filter inside array brackets:
jq -c '[.[] | .Split.result]'
Demo
Note that for filters of the form [.[] | …]
there’s a shorthand function map(…)
, so this is equivalent to the above:
jq -c 'map(.Split.result)'
Demo
Alternatively, if you just wanted to collect all scalars
into an array, traverse the document with ..
and collect the results as before:
jq -c '[..|scalars]'
Demo
For the given input, all of these produce (with the -c
flag compacted into a single line):
["first_image","second_image"]
0