By default DeepDiff ignores private variables. These are field names that start with double underscore.
You can test this by adding a letter to the start of the underscore.
Anyway to preform comparison, simply set the parameter ignore_private_variables to False
That is:
print(DeepDiff(item1, item2, ignore_private_variables=False))
Output:
{'dictionary_item_added': [root['__PythonResult__Modules']['global']], 'dictionary_item_removed': [root['__PythonResult__Modules']['b']]}
Answer from Greg on Stack OverflowZepworks
zepworks.com › deepdiff › current › serialization.html
Serialization — DeepDiff 8.6.1 documentation
Take a look at the above To Json Pickle for an example. Sometimes, it is desired to serialize a Delta object to a list of flat rows. For example, to store them in relation databases. In that case, you can use the Delta.to_flat_rows to achieve the desired outcome. The rows are named tuples and can be converted to dictionaries using ._asdict() >>> from pprint import pprint >>> from deepdiff import DeepDiff, Delta >>> t1 = {"key1": "value1"} >>> t2 = {"field2": {"key2": "value2"}} >>> diff = DeepDiff(t1, t2, verbose_level=2) >>> pprint(diff, indent=2) { 'dictionary_item_added': {"root['field2']":
Videos
PyPI
pypi.org › project › deepdiff
deepdiff · PyPI
Deep Difference and Search of any Python object/data. Recreate objects by adding adding deltas to each other.
» pip install deepdiff
Deviloper's Blog
deviloper.in › advanced-json-diff-checker-in-python-an-in-depth-guide
Advanced JSON Diff Checker in Python: An In-Depth Guide
September 9, 2024 - In this comprehensive guide, we'll dive into the world of JSON diff checking and explore how to build an advanced JSON diff checker in Python. We'll leverage the power of the deepdiff library to perform precise comparisons and the termcolor library to provide a visually appealing and user-friendly ...
Readthedocs
deepdiff.readthedocs.io › en › latest › diff.html
DeepDiff Reference — DeepDiff 4.0.7 documentation
Load DeepDiff object with all the bells and whistles from the json pickle dump.
GitHub
github.com › seperman › deepdiff
GitHub - seperman/deepdiff: DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together.
DeepDiff: Deep Difference of dictionaries, iterables, strings, and ANY other object. DeepSearch: Search for objects within other objects. DeepHash: Hash any object based on their content.
Starred by 2.5K users
Forked by 257 users
Languages Python
Readthedocs
deepdiff.readthedocs.io
DeepDiff OLD 4.0.7 documentation! — DeepDiff 4.0.7 documentation
DeepDiff: Deep Difference of dictionaries, iterables, strings and other objects.
YouTube
youtube.com › watch
1. DeepDiff: Smarter JSON Comparison using Python - YouTube
Learn how to compare JSON like a pro using DeepDiff in Python! 🚀In this episode, we introduce DeepDiff—a powerful tool for QAs and developers to detect chan...
Published October 22, 2025
Zepworks
zepworks.com › deepdiff › current › index.html
DeepDiff 8.6.1 documentation! — DeepDiff 8.6.1 documentation
Get the deep difference of any Python objects. ... DeepDiff For Deep Difference of 2 objects.
Top answer 1 of 2
4
There is probably a better way to do this. But you can parse the returned strings and chain together a new dictionary with the result you want.
json1 = {"spark": {"ttl":3, "poll":34}}
json2 = {"spark": {"ttl":3, "poll":34, "toll":23}, "cion": 34}
deepdiffresult = {'dictionary_item_added': {"root['spark']['toll']", "root['cion']"}}
added = deepdiffresult['dictionary_item_added']
def convert(s, j):
s = s.replace('root','')
s = s.replace('[','')
s = s.replace("'",'')
keys = s.split(']')[:-1]
d = {}
for k in reversed(keys):
if not d:
d[k] = None
else:
d = {k: d}
v = None
v_ref = d
for i, k in enumerate(keys, 1):
if not v:
v = j.get(k)
else:
v = v.get(k)
if i<len(keys):
v_ref = v_ref.get(k)
v_ref[k] = v
return d
added_dict = {}
for added_str in added:
added_dict.update(convert(added_str, json2))
added_dict
#returns:
{'cion': 34, 'spark': {'toll': 23}}
2 of 2
3
Simple Answer, in python have a in-build called Dictdiffer function. can you try this.
$ pip install dictdiffer
Examples:
from dictdiffer import diff
result = diff(json1, json2)
print result == {"spark" : {"toll":23}, "cion":34}
References: DictDiffer
GitHub
github.com › seperman › deepdiff › issues › 566
JSON serialization doesn't work when DeepDiff is part of another dict · Issue #566 · seperman/deepdiff
September 4, 2025 - import json from deepdiff import DeepDiff d1 = dict(a=1, b=2, c=3) d2 = dict(a=1, b=2, c=4, e="new") diff = DeepDiff(d1, d2) print(diff.to_json()) # works fine # --- some_bigger_object = {"diffs": diff} class DeepDiffToDictEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, DeepDiff): return o.to_dict() return super().default(o) class DeepDiffToJsonEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, DeepDiff): return o.to_json() return super().default(o) # raises TypeError: Object of type SetOrdered is not JSON serializable print(json.dumps(some_bigger_object, cls=DeepDiffToDictEncoder)) # raises TypeError: Object of type SetOrdered is not JSON serializable print(json.dumps(some_bigger_object, cls=DeepDiffToJsonEncoder))
Published Sep 04, 2025
Snyk
snyk.io › advisor › deepdiff › functions › deepdiff.deepdiff
How to use the deepdiff.DeepDiff function in deepdiff | Snyk
So first, if there is a Policy attribute, do a DeepDiff of just the JSON parsed from the strings of both, then if they match, remove the elements from the dictionaries. Then there is another DeepDiff on the rest of the state, which wont fail erroneously now that the policy strings have been removed.
GitHub
github.com › RafiC92 › deepdiff
GitHub - RafiC92/deepdiff: Deep Difference and search of any Python object/data.
Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes. Tested on Python 2.7, 3.3, 3.4, 3.5, 3.6, Pypy, Pypy3 ... >>> from deepdiff import DeepDiff # For Deep Difference of 2 objects >>> from deepdiff import DeepSearch # For finding if item exists in an object
Author RafiC92
Zepworks
zepworks.com › deepdiff › current › optimizations.html
Optimizations — DeepDiff 8.6.1 documentation
DeepDiff will automatically use orjson instead of Python’s built-in json library to do json serialization.
Top answer 1 of 4
31
You can use jsondiff
from jsondiff import diff
diff(json1, json2)
... assuming you have json1 and json2 loaded with the json entries from your example (and by the way, you have a missing comma after the 'sex' entry).
2 of 4
23
you can use deepdiff with ignore_order=True
from deepdiff import DeepDiff
t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3]}}
t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 3, 2, 3]}}
ddiff = DeepDiff(t1, t2, ignore_order=True)
print (ddiff)
{}