Cool json git diff command
Nino Filiu

Nino Filiu @ninofiliu

About: Software engineer & visual artist

Location:
Paris
Joined:
Mar 23, 2020

Cool json git diff command

Publish Date: Feb 24 '21
8 1

git diff is great but kinda sucks when reporting about deep keys updates in JSON files, because it only shows the last key, and not the whole object path to the updated key

$ git diff HEAD~1 -- file.json
...
-       "name": "John Doe"
+       "firstName": "John",
+       "lastName": "Doe"
...
Enter fullscreen mode Exit fullscreen mode

But by combining gron with git show $rev:$path, we can have a very pretty output that tells which keys have been updated, and it's almost valid JS!

$ diff <(git show HEAD~1:file.json | gron) <(gron file.json)
< json.users[0].owner.name = "John Doe";
---
> json.users[0].owner.firstName = "John";
> json.users[0].owner.lastName = "Doe";
Enter fullscreen mode Exit fullscreen mode

I found that too elegant not to share. Have fun scripting!

Comments 1 total

Add comment