Reputation: 47971
How can I transform this output:
$ jq -s '.[0] * .[1] * .[2] | to_entries' a.json b.json c.json
[
{
"key" : "SimpleNumber",
"value" : "123"
},
{
"key" : "SimpleString",
"value" : "Hello"
},
{
"key" : "ComplexString",
"value" : "Hello World"
}
]
to:
1)
"SimpleNumber=123" "SimpleString=Hello" "ComplexString=Hello World"
and
2)
SimpleNumber="123" SimpleString="Hello" ComplexString="Hello World"
Upvotes: 0
Views: 120
Reputation: 44182
String interpolation combined with join()
:
jq --raw-output 'map("\"\(join("="))\"") | join(" ")'
to generate
"SimpleNumber=123" "SimpleString=Hello" "ComplexString=Hello World"
Or to it 'by hand' to quote only the value:
jq --raw-output 'map("\(.key)=\"\(.value)\"") | join(" ")'
SimpleNumber="123" SimpleString="Hello" ComplexString="Hello World"
Upvotes: 1
Reputation: 36391
Use string interpolation and put the quotes as you see fit:
jq -r 'map("\"\(.key)=\(.value)\"") | join(" ")'
"SimpleNumber=123" "SimpleString=Hello" "ComplexString=Hello World"
jq -r 'map("\(.key)=\"\(.value)\"") | join(" ")'
SimpleNumber="123" SimpleString="Hello" ComplexString="Hello World"
Upvotes: 1