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

json-diff-rfc6902

v1.3.3

Published

This framework is to compare two JSON data and generate the Patch

Downloads

26

Readme

JSON-Diff

JSON-Diff is to diff two JSON object and generate the patch, which is compliant to JSON Patch RFC6902.

You can use JSON-Diff to

  • diff two JSON object
  • apply patches to get JSON

JSON-Diff is able to handle operations:

Object

  • add
  • remove
  • replace
  • copy
  • move

Array

  • add
  • remove
  • replace
  • copy
  • move
  • permutation

INSTALL

npm

npm install json-diff-rfc6902 --save

bower

bower install json-diff-rfc6902 --save

  • json-diff-rfc6902.js main bundle
  • jdr global variable

API

var jdr = require('json-diff-rfc6902');

// diff the two JSON objects to get the pathes
var jdr_patch = jdr.diff(f_old, f_new [, options]);

// The third parameter is optional, use the object options.
// Default:
options.OBJ_COM = true   // Generate copy and move for object
options.ARR_COM = true   // Generate minimal patch for array
options.HASH_ID = null   // manually set the hash value

// For example, if options.HASH_ID = "title", it will get the property value "title" of the elements in the array, and use them as the hash value to execute the operations transformation algorithem.
var jdr_patch = jdr.diff(f_old, f_new, {OBJ_COM: true, ARR_COM: true, HASH_ID: "title"});

// apply the patches to the f_old object
jdr.apply(f_old, jdr_patch);

TEST

npm install -g mocha

npm install -g fast-json-patch jiff json8-patch rfc6902

cd tests

node diff.js

mocha

Test 1

OBJ_PROP_INS

This is an object where a property is added.

Test 2

OBJ_PROP_DEL

This is an object where a property is removed.

Test 3

OBJ_PROP_MOD

This is an object where a property value is modified.

Test 4

OBJ_PROP_CPY

This is an object where a property is copied.

Test 5

OBJ_PROP_REN

This is an object where a field is renamed.

Test 6

ARR_OBJ_UNSHIFT

This is an array of objects with a insertion at the beginning of the array.

Test 7

ARR_OBJ_PUSH

This is an array of objects with a insertion at the end of the array.

Test 8

ARR_OBJ_RINS

This is an array of objects with a insertion in the middle of the array.

Test 9

ARR_OBJ_SHIFT

This is an array of objects with a deletion of the first element.

Test 10

ARR_OBJ_POP

This is an array of objects with a deletion of the last element

Test 11

ARR_OBJ_RDEL

This is an array of objects with a deletion of the moddle element

Test 12

ARR_OBJ_BREPLACE

This is an array of objects with a replacement of the first element

Test 13

ARR_OBJ_EREPLACE

This is an array of objects with a replacement of the last element

Test 14

ARR_OBJ_MREPLACE

This is an array of objects with a replacement of the middle element

Test 15

ARR_OBJ_CPY

This is an array of objects where a object is copied.

Test 16

ARR_OBJ_PERM1

Permutation of a objects in an array of objects. [a, b, c] => [a, c, b]

Test 17

ARR_OBJ_PERM2

Permutation of a objects in an array of objects. [a, b, c] => [b, c, a]

Test 18

ARR_OBJ_PERM3

Permutation of a objects in an array of objects. [a, b, c] => [b, a, c]

Test 19

ARR_OBJ_PERM4

Permutation of a objects in an array of objects. [a, b, c] => [c, b, a]

Test 20

ARR_OBJ_PERM5

Permutation of a objects in an array of objects. [a, b, c] => [c, a, b]

Test 21

ARR_OBJ_MOD

This is an array of objects where every object is added a field.