Reputation: 3
I am new with jq and I have these json output of an app:
{
"Woonkamer": {
"currentTemperature": 21.8,
"battery": 75,
"isFailed": false
}
}
{
"Hal": {
"currentTemperature": 19.5,
"battery": 48,
"isFailed": false
}
}
{
"Bijkeuken": {
"currentTemperature": 18.4,
"battery": 56,
"isFailed": false
}
}
I want them to join to one json object like:
{
"Woonkamer": {
"currentTemperature": 21.8,
"battery": 75,
"isFailed": false
},
"Hal": {
"currentTemperature": 19.5,
"battery": 48,
"isFailed": false
},
"Bijkeuken": {
"currentTemperature": 18.4,
"battery": 56,
"isFailed": false
}
}
I cannot get figured out how to do that with jq (I read the manual),
Can someone help me?
Upvotes: 0
Views: 203
Reputation: 44182
Use jq's add
, this will concatenate all the input objects;
// Multiple variables holding objects
jq -s add <<< "$j1 $j2 $j3"
// Multiple files holding objects
jq -s add file1 file2 file3
// Command output with multiple columns
command | jq -s add
You can add multiple columns by hand like so;
jq -s '.[0] * .[1] * .[2]' file1 file2 file3
Both options result in:
{
"Woonkamer": {
"currentTemperature": 21.8,
"battery": 75,
"isFailed": false
},
"Hal": {
"currentTemperature": 19.5,
"battery": 48,
"isFailed": false
},
"Bijkeuken": {
"currentTemperature": 18.4,
"battery": 56,
"isFailed": false
}
}
Upvotes: 1