viruschidai / diff-json

A javascript object diff tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array item order matters, however When object in an Array change order, no diff is generated

dhwang opened this issue · comments

Need to be able to show that two items in an array switched order for example

{ a : [ { id: b, value: 1}, {id: a, value: 2}] }

{ a : [ { id: a, value: 2}, {id: b, value: 1}] }

should show a difference as order matters in an array

Looks like it works:

var changesets = require('diff-json');

console.log(changesets.diff(
  { a : [ { id: 'b', value: 1}, {id: 'a', value: 2}] },
  { a : [ { id: 'a', value: 2}, {id: 'b', value: 1}] }));

returns

[ { type: 'update',
    key: 'a',
    embededKey: '$index',
    changes: [ [Object], [Object] ] } ]

yes, it should work by default