Compare πŸ‘₯ and extract πŸ”¬ differences between JSON values

Overview

json-changes

Easily compare changes in JSON-like values. This can be especially useful when you want to compare an incoming payload with a counterpart stored in a database.

npm version CI status

Installation

npm i json-changes

Usage

First, let's define our flags in a file we'll call permissions.js:

const diff = require('json-changes')

const before = { hello: 'world', foo: 'bar', thisPropertyNoLongerExists: true }
const after = { hello: 'world', foo: 'not bar' }

const comparison = diff(before, after)
// returns:
{
  before: {
    foo: 'bar',
    thisPropertyNoLongerExists: true
  },
  after: {
    // Only properties that changed are included
    foo: 'not bar',
    // Properties that have been removed have an undefined value;
    thisPropertyNoLongerExists: undefined
  }
}

It works recursively in nested objects as well:

const before = { nestedObj: {} }
const after = { nestedObj: { evenMoreNestedObject: { thisPropIsNew: 'Hello, new property!' } } }

const comparison = diff(before, after)
// returns:
{
  before: {
    nestedObj: { evenMoreNestedObject: undefined }
  },
  after: {
    nestedObj: {
      evenMoreNestedObject: {
        thisPropIsNew: 'Hello, new property!'
      }
    }
  }
}

undefined values

Encountering an undefined value in the comparison means that the property either did not exist in before or was removed in after.

json-changes is primarily meant to be used to compare JSON, so undefined is assumed to never be used in the payloads being compared.

You might also like...

Compare James Webb Space Telescope images to older images.

Compare James Webb Space Telescope images to older images.

How much more powerful is the James Webb Space Telescope when compared to Hubble? Find out! More info Want to help out? CONTRIBUTING.md Blog post with

Jan 3, 2023

πŸ› οΈ Easily track & compare gas costs estimated by Foundry on each of your Pull Requests!

πŸ”₯ πŸ› οΈ Foundry Gas Diff Reporter Easily compare gas reports generated by Foundry automatically on each of your Pull Requests! How it works Everytime s

Dec 28, 2022

This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

HtmlFormApp Overview This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreads

Oct 23, 2022

Automated testing for single-page applications (SPAs). Small, portable, and easy to use. Click on things, fill in values, await for things exist, etc.

SPA Check Automated testing for single-page applications (SPAs). Small, portable, and easy to use. Click on things, fill in values, await for things e

Dec 23, 2022

Export AWS SSM Parameter Store values in bulk to .env files

aws-parameter-bulk Utility to read parameters from AWS Systems Manager (SSM) Parameter Store in bulk and output them in environment-file or json forma

Oct 18, 2022

This is a library that makes it possible to change the configuration values of the Remix compiler (esbuild).

πŸ’½ remix-esbuild-override ⚠️ While I believe you will most likely get a lot of benefit from using this library, it can sometimes destroy your product.

Dec 22, 2022

πŸš€ Transition number values using easing functions

πŸš€ Transition number values using easing functions

react-transition-value Transition / Animate number values using easing functions See Demos ⚑️ Getting started npm i react-transition-value import {

Dec 15, 2022

Generate deterministic fake values: The same input will always generate the same fake-output.

Generate deterministic fake values: The same input will always generate the same fake-output.

import { copycat } from '@snaplet/copycat' copycat.email('foo') // = '[email protected]' copycat.email('bar') // = 'Thurman.Schowalter668@

Dec 30, 2022

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

🧩 TypeScript Primitives type TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types

Dec 7, 2022
Owner
Joakim Hedlund
Joakim Hedlund
Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values.

@suchipi/is Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values. Usage import { is

Lily Skye 5 Sep 8, 2022
Tiny and fast utility to extract all possible values for a given enum.

Tiny (208B) and fast utility to extract all possible values for a given enum.

Andrea Cappuccio 2 Apr 18, 2022
Simple components showing differences in each major frontend web framework.

Web Frameworks A collection of simple components in each of the leading frontend web frameworks. So far, covering React, Vue, Angular, Svelte and Soli

Daniel Still 21 Nov 27, 2022
Find duplicate object values of your JSON files (VSCode Extension)

JASON Lint VS Code Extension Make your life easier, use this extension to defeat the horror of duplicate values from your JSON files. Very useful when

Leonardo Pizzoquero 3 Oct 20, 2022
JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Hong Minhee (ζ΄ͺ 民憙) 13 Sep 2, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de crΓ©er un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
✨ View all of your GitHub stats and compare your stats with friends, made using nextjs and tailwind.

Octotastic All of your GitHub Stats in one place. Features: View your own stats or any other user's stats. View advanced stats using graphs and charts

ashish 10 Sep 6, 2022
aka Scaletor, take screenshots of a piece of a map and scale/compare with other parts of the map

scale-a-tron A quick-and-dirty map that lets you compare one area to another. Draw a shape around a region, zoom in to another place on the map, and c

Stamen Design 24 Nov 7, 2022
Compare camelized/dasherized/underscored strings each other 🀜🏿 πŸ€›πŸΏ

aynen Compare camelized/dasherized/underscored strings each other Install npm install aynen yarn add aynen Usage import aynen from 'aynen'; aynen('fo

null 4 Mar 25, 2022
Gets system requirement information to compare to the ones shown in Steam.

Steam SysReq Gets system requirement information to compare to the ones shown in Steam. Usage import getSteamSysReq from 'steam-sysreq'; const steamS

Mohammed Keyvanzadeh 3 Nov 15, 2022