temuri
temuri

Reputation: 2807

remove top-level JSON keys that are present in second JSON

I am trying to use jq to remove keys from the first file that exist in the second file.

Given:

a.json:

{"a": 1, "b": 2}

b.json:

{"b": true}

Required contents of diff.json:

{"a": 1}

Question:

What's the jq syntax to subtract these two JSONs?

Thanks!

Upvotes: 0

Views: 206

Answers (1)

oguz ismail
oguz ismail

Reputation: 50795

We had a very similar question yesterday, my answer to that can be adapted for this case as shown below.

$ jq 'delpaths([input | path(.[])])' a.json b.json > diff.json
$ cat diff.json
{
  "a": 1
}

Upvotes: 1

Related Questions