ujsondiff


Nameujsondiff JSON
Version 3.0.1 PyPI version JSON
download
home_pagehttps://github.com/CrispyCrafter/ujsondiff
SummaryDiff JSON and JSON-like structures in Python
upload_time2022-12-13 06:55:07
maintainer
docs_urlNone
authorBP Greyling
requires_python>=3.8,<4.0
licenseMIT
keywords json diff diffing difference patch delta dict lcs micropython
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ## ujsondiff
========

Diff JSON and JSON-like structures in Python.

# Installation
------------

`pip install ujsondiff`

# Quickstart
----------

```
>>> import ujsondiff as jd
>>> from ujsondiff import diff

>>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4})
{'c': 4, 'b': 3, delete: ['a']}

>>> diff(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])
{insert: [(3, 'd')]}

>>> diff(['a', 'b', 'c'], ['a', 'c'])
{delete: [1]}

# Typical diff looks like what you'd expect...
>>> diff({'a': [0, {'b': 4}, 1]}, {'a': [0, {'b': 5}, 1]})
{'a': {1: {'b': 5}}}

# ...but similarity is taken into account
>>> diff({'a': [0, {'b': 4}, 1]}, {'a': [0, {'c': 5}, 1]})
{'a': {insert: [(1, {'c': 5})], delete: [1]}}

# Support for various diff syntaxes
>>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}, syntax='explicit')
{insert: {'c': 4}, update: {'b': 3}, delete: ['a']}

>>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}, syntax='symmetric')
{insert: {'c': 4}, 'b': [2, 3], delete: {'a': 1}}

# Special handling of sets
>>> diff({'a', 'b', 'c'}, {'a', 'c', 'd'})
{discard: set(['b']), add: set(['d'])}

# Load and dump JSON
>>> print diff('["a", "b", "c"]', '["a", "c", "d"]', load=True, dump=True)
{"$delete": [1], "$insert": [[2, "d"]]}

# NOTE: Default keys in the result are objects, not strings!
>>> d = diff({'a': 1, 'delete': 2}, {'b': 3, 'delete': 4})
>>> d
{'delete': 4, 'b': 3, delete: ['a']}
>>> d[jd.delete]
['a']
>>> d['delete']
4
# Alternatively, you can use marshal=True to get back strings with a leading $
>>> diff({'a': 1, 'delete': 2}, {'b': 3, 'delete': 4}, marshal=True)
{'delete': 4, 'b': 3, '$delete': ['a']}

```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/CrispyCrafter/ujsondiff",
    "name": "ujsondiff",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "json,diff,diffing,difference,patch,delta,dict,LCS,micropython",
    "author": "BP Greyling",
    "author_email": "bpgreyling@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ab/b3/01aaad0fb76246a89c725bc04afe51316adce7003d66d65f4b129a1f8134/ujsondiff-3.0.1.tar.gz",
    "platform": null,
    "description": "## ujsondiff\n========\n\nDiff JSON and JSON-like structures in Python.\n\n# Installation\n------------\n\n`pip install ujsondiff`\n\n# Quickstart\n----------\n\n```\n>>> import ujsondiff as jd\n>>> from ujsondiff import diff\n\n>>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4})\n{'c': 4, 'b': 3, delete: ['a']}\n\n>>> diff(['a', 'b', 'c'], ['a', 'b', 'c', 'd'])\n{insert: [(3, 'd')]}\n\n>>> diff(['a', 'b', 'c'], ['a', 'c'])\n{delete: [1]}\n\n# Typical diff looks like what you'd expect...\n>>> diff({'a': [0, {'b': 4}, 1]}, {'a': [0, {'b': 5}, 1]})\n{'a': {1: {'b': 5}}}\n\n# ...but similarity is taken into account\n>>> diff({'a': [0, {'b': 4}, 1]}, {'a': [0, {'c': 5}, 1]})\n{'a': {insert: [(1, {'c': 5})], delete: [1]}}\n\n# Support for various diff syntaxes\n>>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}, syntax='explicit')\n{insert: {'c': 4}, update: {'b': 3}, delete: ['a']}\n\n>>> diff({'a': 1, 'b': 2}, {'b': 3, 'c': 4}, syntax='symmetric')\n{insert: {'c': 4}, 'b': [2, 3], delete: {'a': 1}}\n\n# Special handling of sets\n>>> diff({'a', 'b', 'c'}, {'a', 'c', 'd'})\n{discard: set(['b']), add: set(['d'])}\n\n# Load and dump JSON\n>>> print diff('[\"a\", \"b\", \"c\"]', '[\"a\", \"c\", \"d\"]', load=True, dump=True)\n{\"$delete\": [1], \"$insert\": [[2, \"d\"]]}\n\n# NOTE: Default keys in the result are objects, not strings!\n>>> d = diff({'a': 1, 'delete': 2}, {'b': 3, 'delete': 4})\n>>> d\n{'delete': 4, 'b': 3, delete: ['a']}\n>>> d[jd.delete]\n['a']\n>>> d['delete']\n4\n# Alternatively, you can use marshal=True to get back strings with a leading $\n>>> diff({'a': 1, 'delete': 2}, {'b': 3, 'delete': 4}, marshal=True)\n{'delete': 4, 'b': 3, '$delete': ['a']}\n\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Diff JSON and JSON-like structures in Python",
    "version": "3.0.1",
    "split_keywords": [
        "json",
        "diff",
        "diffing",
        "difference",
        "patch",
        "delta",
        "dict",
        "lcs",
        "micropython"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "f4726808b340bc4da5ebe772054376d5",
                "sha256": "531e15353afb2b7e93aff647bc0192db2a0bae885acdbcd5a5a790924c088dda"
            },
            "downloads": -1,
            "filename": "ujsondiff-3.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f4726808b340bc4da5ebe772054376d5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 5877,
            "upload_time": "2022-12-13T06:55:05",
            "upload_time_iso_8601": "2022-12-13T06:55:05.777292Z",
            "url": "https://files.pythonhosted.org/packages/0e/b8/5d87d77420d6a65d0bcc3c19b84368e163dce9098f88fb07284e0150e381/ujsondiff-3.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "3821cc48dee3360a5d33c438ae684d07",
                "sha256": "3151951d23f03adb56cc3b18ad913770445f8339440f0d5e0829b3a5ebcdd0a5"
            },
            "downloads": -1,
            "filename": "ujsondiff-3.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3821cc48dee3360a5d33c438ae684d07",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 5827,
            "upload_time": "2022-12-13T06:55:07",
            "upload_time_iso_8601": "2022-12-13T06:55:07.879122Z",
            "url": "https://files.pythonhosted.org/packages/ab/b3/01aaad0fb76246a89c725bc04afe51316adce7003d66d65f4b129a1f8134/ujsondiff-3.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-13 06:55:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "CrispyCrafter",
    "github_project": "ujsondiff",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ujsondiff"
}
        
Elapsed time: 0.15095s