jlevy / pdiffjson

View and diff JSON the easy way
Apache License 2.0
74 stars 5 forks source link

pjson and pdiffjson

example usage

Installation

  1. Ensure you have jq and colordiff on your system.

    Use brew install jq colordiff on Mac, apt-get install jq colordiff or equivalent on Linux.

  2. Install the script anywhere you like. Simplest:

    $ npm install -g pdiffjson

    Or copy pjson and pdiffjson to /usr/local/bin by hand!

Usage

$ pdiffjson
Usage: pdiffjson [--sort-arrays] [diff options] file1.json file2.json

Show pretty-printed, colored diff of normalized JSON. Uses less to
paginate the output. Allows a readable diff of any JSON, ignoring all
non-semantic differences of whitespace and key ordering.

Fields of each object are output with the keys in sorted order
prior to calling diff, so insignificant differences of key order
are ignored. The --sort-arrays option also enables recursive sorting
of all array values, so all differences in ordering within arrays
are ignored.

This is a "semi-structural diff", meaning it shows only structural
(semantic) changes but the diff is shown syntactically on JSON output,
which actually makes it more readable and flexible than a true
structural diff.

Works on large files since it relies only on diff and jq.

By default calls diff without arguments, yielding a unified diff. But
it can be helpful to add standard diff arguments to refine the type of
output, such as:
-c (contextual diff),
-C2 (contextual diff with two lines of context), or
-U5 (unified diff with 5 lines of context).

$

Related Work