gron is an incredible tool that makes JSON greppable. But it also makes it diffable, which is great if you have JSON files in Git.
To use gron to diff JSON in Git, save the json-diff script below and make it executable. Then add a difftool as shown in gitconfig, and optionally create an alias to invoke it more easily. Then try it:
git init
echo '{"foo":42,"bar":"hello"}' > foo.json
git add foo.json && git commit -m 'Initial commit.'
echo '{"foo":43,"bar":"hello"}' > foo.json
git jdiff
will give you:
--- a/foo.json
+++ b/foo.json
@@ -1,3 +1,3 @@
json = {};
json.bar = "hello";
-json.foo = 42;
+json.foo = 43;
You’re absolutely right. I have the
-Rin myLESSenvironment variable*, so I didn’t even realise it.I didn’t understand the second part of your comment, though.
* I did
export LESS='--RAW-CONTROL-CHARS --ignore-case --no-init --line-numbers'.--RAW-CONTROL-CHARSis-R,--ignore-casemeans I can do a case insensitive search by using a lowercase search string, but it becomes case sensitive if there are uppercase characters in it,--no-initdoes not clear the screen on quitting, I prefer it that way, and--line-numbersmakes it faster on large files, if I remember right.