tst2005sh / jsondiff

0 stars 0 forks source link

jsondiff

A jsondiff tool.

{
  "People": ["John", "Bryan"],
  "City": "Boston",
  "State": "MA"
}
{
  "People": ["John", "Bryan", "Carla"],
  "City": "Boston",
  "State": "MA"
}
{
  "People": ["John", "Bryan", "Carla"],
  "City": "Boston",
  "State": "ElseWhere"
}

sample of use

[ano@nymous]~/jsondiff$ ./bin/jsondiff.via-lib samples/a.json samples/b.json # same content, no diff
[ano@nymous]~/jsondiff$ ./bin/jsondiff.via-lib samples/a.json samples/c.json
["+", {".People[]":"Carla"}]
[ano@nymous]~/jsondiff$ ./bin/jsondiff.via-lib samples/a.json samples/d.json
["+", {".People[]":"Carla"}]
["-", {".State":"MA"}]
["+", {".State":"ElseWhere"}]

WIP

["+", {".People[]":"Carla"}]
["-", {".State":"MA"}]
["+", {".State":"ElseWhere"}]
jq -s -c 'map( .[1] |= ((to_entries|(map(.key, .value)))  )|flatten(1) ) |.[]'
["+",".People[]","Carla"]
["-",".State","MA"]
["+",".State","ElseWhere"]
jq -s -c -r 'map( (.[1]|sub("^\\.";"")) + ("") + (" "*(15 - (.[1]|length)))+ "" + .[0] + " " + .[2]) |.[]'
People[]      + Carla
State         - MA
State         + ElseWhere