0

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?

2
  • 1
    How big is the JSON? Commented Mar 11, 2021 at 18:09
  • @Inian It is about 1000 characters Commented Mar 11, 2021 at 20:32

1 Answer 1

1

Use '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 

Manually

You can add multiple columns by hand like so;

jq -s '.[0] * .[1] * .[2]' file1 file2 file3 

Result

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 } } 
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer worked for me. I piped the result to the following jq command: code | jq -s '.[0] * .[1] * .[2]'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.