Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Javascript library to figure out the changes between json data.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
dist
lib
test
.gitignore
HISTORY.md
LICENSE
README.md
package.json

README.md

Data Diff

A library that calculates the changes from one json object to another. It was designed for figuring out the differences in data returned from the server so only the models that change would trigger updates to the views. It will work in both the browser and in node.

Example

First response from server:

[
  {
    "id": 1,
    "name": "James Brown",
    "status": 1,
    "counts": {
      "fingers": 5,
      "toes": 5
    }
  },
  {
    "id": 2,
    "name": "Jane Doe",
    "status": 1,
    "counts": {
      "fingers": 5,
      "toes": 5
    }
  }
]

Second response from server:

[
  {
    "id": 1,
    "name": "James Brown",
    "status": 1,
    "counts": {
      "fingers": 5,
      "toes": 5
    }
  },
  {
    "id": 2,
    "name": "Jane Doe",
    "status": 2,
    "counts": {
      "fingers": 5,
      "toes": 10 
    }
  },
  {
    "id": 3,
    "name": "John Smith",
    "status": 2,
    "counts": {
      "fingers": 5,
      "toes": 5
    }
  }
]

After running through dataDiff

[
  {
    "id": 2,
    "status": 2,
    "counts": {
      "toes": 10 
    }
  },
  {
    "id": 3,
    "name": "John Smith",
    "status": 2,
    "counts": {
      "fingers": 5,
      "toes": 5
    }
  }
]

Only the new items and the differences get returned.

Usage

var diff = dataDiff(data1, data2, 'id'); //id is the key to match the two data points together

Installation

Node: npm install data-diff

Browser: Development | Production

Something went wrong with that request. Please try again.