Simple things to do using jq
# turn a delimted string into an array:
echo '"2368;3924"' | jq 'split(";")
[
"2368",
"3924"
]# turn array elements into numbers:
echo '["2368","3924"]' | jq 'map_values(.|tonumber)'A one-liner of both: echo '"2368;3924"' | jq 'split(";")|map_values(.|tonumber)'
Output array of strings as unquoted lines:
echo '["a","b"]["c"]' |jq -r '.[]'
a
b
cHere we filter based on multiple object property restrictions, then output array values.
The select((.arr|length)>0) element is critical to avoid passing null farther down the stream.
echo '[
{
"a": true,
"b": "good",
"arr": ["v1", "v2"]
},
{ "a": false,
"b": "good",
"arr": ["v3", "v4"]
},
{ "a": true,
"b": "bad",
"arr": ["v5", "v6"]
},
{ "a": true,
"b": "good"
}
]' |jq -r '.[]|select((.arr|length)>0 and .b=="good" and .a)|.arr|.[]'
v1
v2