Morphie
Morphie

Reputation: 13

Merge json files using jq (one input object per file -> one larger output object, not a list)

I am merging two json files using "jq -s . file1 file2", but I want them to get merged without comma separation. Also it shouldn't start with []

file 1:

{
  "node1": {
    "Environment": "PRD",
    "OS": "linux"
  },
  "node2": {
    "Environment": "NPR",
    "OS": "linux"
  }
}

file 2:

{
  "node3": {
    "Environment": "PRD",
    "OS": "linux"
  },
  "node4": {
    "Environment": "NPR",
    "OS": "linux"
  }
}

Output using jq -s . file 1 file 2

[
    {
      "node1": {
        "Environment": "PRD",
        "OS": "linux"
      },
      "node2": {
        "Environment": "NPR",
        "OS": "linux"
      }
    },
    {
      "node3": {
        "Environment": "PRD",
        "OS": "linux"
      },
      "node4": {
        "Environment": "NPR",
        "OS": "linux"
      }
    }
]

Required output:

{
  "node1": {
    "Environment": "PRD",
    "OS": "linux"
  },
  "node2": {
    "Environment": "NPR",
    "OS": "linux"
  },
    "node3": {
    "Environment": "PRD",
    "OS": "linux"
  },
  "node4": {
    "Environment": "NPR",
    "OS": "linux"
  }
} 

Can anyone help me finding solution to this, Thank you!

Upvotes: 0

Views: 462

Answers (1)

peak
peak

Reputation: 116967

One option slong the lines of your attempt:

jq -s add file1 file2

Another:

   jq -n 'input+input' file1 file2

Upvotes: 1

Related Questions