Skip to content

Instantly share code, notes, and snippets.

@oscherler
Last active August 28, 2024 14:40
Show Gist options
  • Select an option

  • Save oscherler/22eb60eb78a4e4e89e0506578e8b820a to your computer and use it in GitHub Desktop.

Select an option

Save oscherler/22eb60eb78a4e4e89e0506578e8b820a to your computer and use it in GitHub Desktop.

Revisions

  1. oscherler revised this gist Aug 15, 2017. No changes.
  2. oscherler revised this gist Aug 15, 2017. 2 changed files with 27 additions and 4 deletions.
    24 changes: 23 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,25 @@
    # jsondiff: diff JSON in Git using gron

    [`gron`](https://github.com/tomnomnom/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.
    [`gron`](https://github.com/tomnomnom/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:

    ```diff
    --- a/foo.json
    +++ b/foo.json
    @@ -1,3 +1,3 @@
    json = {};
    json.bar = "hello";
    -json.foo = 42;
    +json.foo = 43;
    ```
    7 changes: 4 additions & 3 deletions gitconfig
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    [alias]
    jdiff = difftool -t jsondiff -y

    [difftool "jsondiff"]
    cmd = "/path/to/json-diff $LOCAL $REMOTE"

    [alias]
    jdiff = difftool -t jsondiff -y

  3. oscherler renamed this gist Aug 15, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @invalid-email-address Anonymous created this gist Aug 15, 2017.
    5 changes: 5 additions & 0 deletions .gitconfig
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    [alias]
    jdiff = difftool -t jsondiff -y

    [difftool "jsondiff"]
    cmd = "/path/to/json-diff $LOCAL $REMOTE"
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # jsondiff: diff JSON in Git using gron

    [`gron`](https://github.com/tomnomnom/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.
    20 changes: 20 additions & 0 deletions json-diff
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/zsh

    # gron: https://github.com/tomnomnom/gron
    GRON=/usr/local/bin/gron
    DIFF=/usr/bin/diff
    # colordiff: https://www.colordiff.org
    COLORDIFF=/usr/bin/colordiff

    # use colordiff in interactive mode, diff otherwise
    if [ -t 1 ]
    then
    DIFFER=${COLORDIFF}
    else
    DIFFER=${DIFF}
    fi

    LOCAL="$1"
    REMOTE="$2"

    "${DIFFER}" -u --label "a/$REMOTE" --label "b/$REMOTE" <( "$GRON" < "$LOCAL" ) <( "$GRON" < "$REMOTE" ) | less