Comparing two json files : shell scripting

diff, jq, json, shell

Solution

Just use diff. Like in

diff --unified file1.json file2.json

Problem

I would like to compare two json files which look like the following: ``` [ { "type" : 1, "children" : { "nsubj" : { "role" : "topic", "POS" : [ "noun" ] } }, "role" : "vehicle", "POS" : [ "noun" ] }, ``` and the other is in the similar format, but there are some differences between the two because one json file is made up of 3336 lines, while another is made up of 3724 lines. I would like to write a shell script which would compare the two line by line and whenever it finds a difference, output the line number where the difference occurred.

Original source

Related problems