|
This is neat. I decided to diff two pods in a replicated Kubernetes service. It seemed that it was going to take forever to run, so I just wrote a short Go program to do the same thing (load two JSON files into a map[string]interface{}, cmp.Diff them) while it was going: https://gist.github.com/jrockway/73982949b3d2ce9b443528042c4... My program runs in less than 10 milliseconds (/usr/bin/time reports 0.00 seconds), and graphtage takes 5 minutes and 17 seconds. I'm 317,000x faster! (Not including the time to write the program; if you do that, then it's about even assuming graphtage took 0 seconds to write.) Graphtage prints the entire file in JQ colors, with diffs inside fields colored red and green, which I love: ...
"hostIP": "10.136.13̟9̟2̶1̶.139̟1̶",
"podIP": "10.244.1.18̟6̟7̶",
...
(My terminal can't display the dots under the numbers and the strikethrough, but it looks great on HN! I really love it.)My program produces relatively boring line-by-line diffs: - "hostIP": string("10.136.121.131"),
+ "hostIP": string("10.136.139.139"),
"phase": string("Running"),
- "podIP": string("10.244.1.17"),
+ "podIP": string("10.244.1.186"),
Honestly, I get what I want out of mine, and wait 317,000x less time, so... I probably won't be using this on a daily basis. But I will be stealing those dots and Unicode strikethroughs. |
Usecases might be a little bit different, but please allow me to share my solution.
The problem with diffing JSON and yaml is, that these formats aren't line based and hashes don't need to be ordered. But there is gron to turn json into a greppable line-based format [1]. Then you can sort. The sorted output is possible to diff now and then you can color the diff output with delta or a similar tool [2].
This output provides a lot of context for me to see and understand the differences.[1] gron https://github.com/tomnomnom/gron
[2] delta https://github.com/dandavison/delta