I would like to take the json output of window values from a program. The output of it currently is:
[
3067,
584
]
[
764,
487
]
But I need it to be formatted like: 3067,584 764x487
. How would I go about doing this using jq or other commands?
I'm not very experienced with jq and json formatting in general, so I'm not really sure where to start. I have tried looking this up but am still not really sure how to do it.
CodePudding user response:
A solution that does not --slurp
would be using input
for every other array:
jq -r 'join(",") " " (input|join("x"))'
3067,584 764x487
CodePudding user response:
If your input is a stream of JSON arrays, you could use jq's -s
/--slurp
command-line option. Join the first array with comma, the second array with "x"; and finally join both strings with a space:
$ jq -sr '[(.[0]|join(",")), (.[1]|join("x"))] | join(" ")' <<JSON
[
3067,
584
]
[
764,
487
]
JSON
3067,584 764x487