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 🙏

© 2026 – Pkg Stats / Ryan Hefner

flat-json-diff

v0.1.1

Published

An experimental library to diff JSON objects/arrays by flattening them. It can create a patch between two JSON objects/arrays, and apply the patch to another JSON object/array.

Readme

flat-json-diff

test codecov

An experimental library to diff JSON objects/arrays by flattening them. It can create a patch between two JSON objects/arrays, and apply the patch to another JSON object/array. Use by bookmark-to-gist.

Installation

npm install flat-json-diff

Usage

import {createPatch, applyPatch} from "flat-json-diff";

const a = [
  {title: "foo", tags: ["a", "b"]},
  {title: "bar", tags: ["b", "c"]},
];
const b = [
  {title: "foo", tags: ["a", "b", "d"]},
  {title: "bar", tags: ["c"]},
  {title: "baz", tags: []},
];
const patch = createPatch(a, b);
const c = applyPatch([
  {title: "bak", tags: ["x"]},
  {title: "foo", tags: []},
  {title: "bar", tags: ["b"]},
], patch);
console.log(c);
// [
//   { title: 'bak', tags: ["x"] }
//   { title: 'foo', tags: ["d"] },
//   { title: 'bar', tags: [] },
//   { title: 'baz', tags: [] }
// ]

How it works

The library flattens the JSON objects/arrays to diff-friendly lines, diffs the lines to create a patch.

When applying the patch, it flattens the target object/array to lines, apply the patch to the lines, and finally unflattens it back to JSON.

Limitations

There are some limitations: https://github.com/kpdecker/jsdiff

Regardless of fuzzFactor, lines to be deleted in the hunk must be present for a hunk to match, and the context lines immediately before and after an insertion must match exactly.

  1. Modifying a deleted line/Deleting a modified line will always fail.
  2. When adding property, the property before/after the changed property must be the same. Ideally, adding an object property should always succeed.

API references

Check the .d.ts file for TypeScript type definitions.

Alternatives

Because I'm working with bookmark JSON diff, it is crucial to detect move operations. Also bookmarks don't have an object ID, so most of the simple solutions won't work well.

  • diff: The underlying diff library used in this project. It is designed for text diff.

Other json diff tools:

  • rfc6902: Support remove, add, replace.
  • mini-rfc6902: A minimal RFC6902 implementation.
  • json-diff-ts: Support object ID. No move operation.
  • diffptch: Treats arrays as non-ordered set.
  • json-diff-kit: Support multiple array diff methods. No move operation.
  • jsondiffpatch: Probably the most robust JSON diff library. Uses object hash to detect move operations.

The best solution should be something like:

  1. Suppose we have three versions: A -> B, A -> C, and we need a merge of B and C.
  2. Diff A -> B to get a patch P1.
  3. Diff A -> C to get a patch P2.
  4. According the information on A, merge P1 and P2 to get P3.
  5. Apply P3 to A to get the merged result.

When diffing arrays, it should calculate the smallest changes between two arrays, considering move, add, delete, and modify operations, with munkres or similar algorithms.

Changelog

  • 0.1.1 (Nov 28, 2025)

    • Fix: include types.
  • 0.1.0 (Nov 28, 2025)

    • First release