1.0.0 • Published 9 years ago

diff-a-json v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

Diff a JSON

Will fetch, sort (by key), and diff JSON data from 2 given sources (local file or API request).

As default, before comparing the data, each object will be sorted to depth=infinity in order to get the most accurate comparison possible.

Examples

diffajson somedata.json http://example.com/json-api-request?a=1 --sidebyside

diffajson ~/path/to/somedata.json http://example.com/json-api-request?a=1 \
	--savelocal --sidebyside --saveas diff.diff

diffajson http://example.com/json-api-request?a=1 http://example.com/json-api-request?a=2 \
	--savelocal --saveonly

Install

npm install -g diffajson

Arguments

namedescription
--nosortdisables sorting the json object before diff
--savelocalwill save the fetched json files locally as left-timestamp.json and right-timestamp.json
--saveonlywill not run actual diff, to be used in conjunction with --savelocal
--sidebysidewill return the diff in a side-by-side view
--saveas filenamewill save the diff instead of outputting it

Caveats and Workarounds

Authentication (except for Basic Auth) is not currently built-in. Hint: to fetch a file from a source with cookie-based Authentication, do the following:

curl -XPOST https://example.com/auth/signin --data "user=username&password=userpassword" -c cookies
curl http://example.com/json-api-request -b cookies >> data.json