Name | jsondiff JSON |
Version |
2.2.1
JSON |
| download |
home_page | None |
Summary | Diff JSON and JSON-like structures in Python |
upload_time | 2024-08-29 04:09:06 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | The MIT License (MIT) Copyright (c) 2015 Zoomer Analytics LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
json
diff
diffing
difference
patch
delta
dict
lcs
|
VCS |
|
bugtrack_url |
|
requirements |
pyyaml
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# jsondiff
Diff JSON and JSON-like structures in Python.
## Installation
``pip install jsondiff``
## Quickstart
```python
>>> import jsondiff as jd
>>> from jsondiff 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}}}
# You can exclude some jsonpaths from the diff (doesn't work if the value types are different)
>>> diff({'a': 1, 'b': {'b1': 20, 'b2': 21}, 'c': 3}, {'a': 1, 'b': {'b1': 22, 'b2': 23}, 'c': 30}, exclude_paths=['b.b1', 'c'])
{'b': {'b2': 23}}
# ...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}}
>>> diff({'list': [1, 2, 3], "poplist": [1, 2, 3]}, {'list': [1, 3]}, syntax="rightonly")
{"list": [1, 3], delete: ["poplist"]}
# 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']}
```
## Command Line Client
Usage:
```
jdiff [-h] [-p] [-s {compact,symmetric,explicit}] [-i INDENT] [-f {json,yaml}] first second
positional arguments:
first
second
optional arguments:
-h, --help show this help message and exit
-p, --patch
-s {compact,symmetric,explicit}, --syntax {compact,symmetric,explicit}
Diff syntax controls how differences are rendered (default: compact)
-i INDENT, --indent INDENT
Number of spaces to indent. None is compact, no indentation. (default: None)
-f {json,yaml}, --format {json,yaml}
Specify file format for input and dump (default: json)
```
Examples:
```bash
$ jdiff a.json b.json -i 2
$ jdiff a.json b.json -i 2 -s symmetric
$ jdiff a.yaml b.yaml -f yaml -s symmetric
```
## Development
Install development dependencies and test locally with
```bash
pip install -r requirements-dev.txt
# ... do your work ... add tests ...
pytest
```
## Installing From Source
To install from source run
```bash
pip install .
```
This will install the library and cli for `jsondiff` as well as its runtime
dependencies.
## Testing before release
```bash
python -m build
twine check dist/*
```
Raw data
{
"_id": null,
"home_page": null,
"name": "jsondiff",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "json, diff, diffing, difference, patch, delta, dict, LCS",
"author": null,
"author_email": "Zoomer Analytics LLC <eric.reynolds@zoomeranalytics.com>",
"download_url": "https://files.pythonhosted.org/packages/35/48/841137f1843fa215ea284834d1514b8e9e20962bda63a636c7417e02f8fb/jsondiff-2.2.1.tar.gz",
"platform": null,
"description": "# jsondiff\n\nDiff JSON and JSON-like structures in Python.\n\n## Installation\n\n``pip install jsondiff``\n\n## Quickstart\n\n```python\n>>> import jsondiff as jd\n>>> from jsondiff 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# You can exclude some jsonpaths from the diff (doesn't work if the value types are different)\n>>> diff({'a': 1, 'b': {'b1': 20, 'b2': 21}, 'c': 3}, {'a': 1, 'b': {'b1': 22, 'b2': 23}, 'c': 30}, exclude_paths=['b.b1', 'c'])\n{'b': {'b2': 23}}\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>>> diff({'list': [1, 2, 3], \"poplist\": [1, 2, 3]}, {'list': [1, 3]}, syntax=\"rightonly\")\n{\"list\": [1, 3], delete: [\"poplist\"]}\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\n## Command Line Client\n\nUsage:\n```\njdiff [-h] [-p] [-s {compact,symmetric,explicit}] [-i INDENT] [-f {json,yaml}] first second\n\npositional arguments:\n first\n second\n\noptional arguments:\n -h, --help show this help message and exit\n -p, --patch\n -s {compact,symmetric,explicit}, --syntax {compact,symmetric,explicit}\n Diff syntax controls how differences are rendered (default: compact)\n -i INDENT, --indent INDENT\n Number of spaces to indent. None is compact, no indentation. (default: None)\n -f {json,yaml}, --format {json,yaml}\n Specify file format for input and dump (default: json)\n```\n\nExamples:\n\n```bash\n$ jdiff a.json b.json -i 2\n\n$ jdiff a.json b.json -i 2 -s symmetric\n\n$ jdiff a.yaml b.yaml -f yaml -s symmetric\n```\n\n## Development\n\nInstall development dependencies and test locally with\n\n```bash\npip install -r requirements-dev.txt\n# ... do your work ... add tests ...\npytest\n```\n\n## Installing From Source\n\nTo install from source run\n\n```bash\npip install .\n```\n\nThis will install the library and cli for `jsondiff` as well as its runtime\ndependencies.\n\n\n## Testing before release\n\n```bash\npython -m build\ntwine check dist/*\n```\n",
"bugtrack_url": null,
"license": "The MIT License (MIT) Copyright (c) 2015 Zoomer Analytics LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Diff JSON and JSON-like structures in Python",
"version": "2.2.1",
"project_urls": {
"Bug Tracker": "https://github.com/xlwings/jsondiff/issues",
"Homepage": "https://github.com/xlwings/jsondiff"
},
"split_keywords": [
"json",
" diff",
" diffing",
" difference",
" patch",
" delta",
" dict",
" lcs"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6394a8066f84d62ab666d61ef97deba1a33126e3e5c0c0da2c458ada17053ed6",
"md5": "2cc12e1accd5ff8c3b12f4822faa350f",
"sha256": "b1f0f7e2421881848b1d556d541ac01a91680cfcc14f51a9b62cdf4da0e56722"
},
"downloads": -1,
"filename": "jsondiff-2.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2cc12e1accd5ff8c3b12f4822faa350f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 13440,
"upload_time": "2024-08-29T04:09:04",
"upload_time_iso_8601": "2024-08-29T04:09:04.955348Z",
"url": "https://files.pythonhosted.org/packages/63/94/a8066f84d62ab666d61ef97deba1a33126e3e5c0c0da2c458ada17053ed6/jsondiff-2.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3548841137f1843fa215ea284834d1514b8e9e20962bda63a636c7417e02f8fb",
"md5": "af6d531ddf512ab980847334dd2ffa57",
"sha256": "658d162c8a86ba86de26303cd86a7b37e1b2c1ec98b569a60e2ca6180545f7fe"
},
"downloads": -1,
"filename": "jsondiff-2.2.1.tar.gz",
"has_sig": false,
"md5_digest": "af6d531ddf512ab980847334dd2ffa57",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 26649,
"upload_time": "2024-08-29T04:09:06",
"upload_time_iso_8601": "2024-08-29T04:09:06.201297Z",
"url": "https://files.pythonhosted.org/packages/35/48/841137f1843fa215ea284834d1514b8e9e20962bda63a636c7417e02f8fb/jsondiff-2.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-29 04:09:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "xlwings",
"github_project": "jsondiff",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "pyyaml",
"specs": []
}
],
"lcname": "jsondiff"
}