Skip to content

Handling of arrays that are the same but ordered differently #29

Description

@chrisjameslennon

Not really a bug I suppose but where you have two arrays in an object that are identical but in a different order diffler sees these as totally different arrays.

    const obj1 = {
        myArray: [
            { foo: 'bar' },
            { baz: 'bat' }
        ]
    }

    const obj2 = {
        myArray: [
            { baz: 'bat' },
            { foo: 'bar' }
        ]
    }

    const diff = diffler(obj1, obj2)

    console.log(JSON.stringify(diff))

gives

{"myArray":{"0":{"foo":{"from":"bar","to":null},"baz":{"from":null,"to":"bat"}},"1":{"baz":{"from":"bat","to":null},"foo":{"from":null,"to":"bar"}}}}

so would be nice to have an option to ignore ordering in arrays

but even if you accept that the order does matter I am not sure how 'human readable' this output is? But I am sure this is pretty complex stuff I wouldn't like to try ;-)

This library seems to fill a gap I am searching for this kind of tool to compare changes between json objects.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions