build patch from two json data, and apply it.
Python
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
README.md

README.md

JsonDiff

Transforma json like data in a set of key/value.

Works with json like data, it should works with msgpack or bson or even tnetstrings.

Exemple

Normalisation

{'age': 42,
'like': {
    'food': 'ramen'},
'name': 'Robert',
'tags': ['pim', 'pam', 'poum']}

Will be transformed to

set([
    ('name', 'Robert'),
    ('age', 42),
    ('tags[2]', 'poum'),
    ('tags[1]', 'pam'),
    ('like.food', 'ramen'),
    ('tags[0]', 'pim')])

Diff

data1 = {"age": 42,
        "name": "Bob",
        "food": "okonomiyaki"
        }
data2 = {"name": "Casimir",
        "Location": "Torcy",
        "age": 42
        }
assert diff(data1, data2) == {
    '-food': 'okonomiyaki',
    'name': 'Casimir',
    '+Location': 'Torcy'}

Key are unique, patch don't have to remove and add data.

Licence

MIT © Mathieu Lecarme 2012