npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pdiffjson

v0.3.0

Published

diff JSON the easy way

Downloads

12

Readme

pdiffjson

  • pdiffjson is a one-liner bash script that’s non-obvious and useful enough more developers should have it at their fingertips. It simply combines jq, diff, colordiff, and less to normalize and then diff.
  • One of the simplest and fastest ways to get prettily printed, colored, paginated diffs of JSON files. Ignores all irrelevant whitespace and key ordering on collections objects. Just shows you visually what’s different between two files.
  • Not a fancy web UI or a library.
  • Works on large files other tools barf on, thanks to jq’s speed.
  • Shows context around each difference in a customizable way, thanks to diff.
  • Scrollable and searchable output (use space, /), thanks to less.
  • Installs quickly anywhere, thanks to bash.
  • Extra bonus pjson command that colorizes and pretty-prints only.
  • The feature list is longer than the code! 🤯😀

example usage

Installation

$ npm install -g pdiffjson

Or copy the damn bash file to /usr/local/bin by hand. Also ensure you have jq and colordiff as well (brew install jq colordiff on Mac).

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

  • Many websites like jsondiff offer JSON diff functionality but offer no command line, don’t work on large files, and are not good for sensitive data.
  • jsondiffpatch is a powerful JavaScript library to do JSON diff and patch. Has a command line. Shows a pure structural diff. No semi-structured diff with context.
  • diff-json is another useful JavaScript library with a command-line interface. Rather slow on larger (multi-megabyte) files, with no incremental output.
  • jd is a powerful Go command line tool. It handles diff and patching. It allows more flexible diffs options on arrays (set and bag). No colored output or diff output options to show more context, as with diff, so the output seems less clear to read.