I want to exclude Key7 and Key8 from the DeepDiff comparison. Even if the values of key7 and key 8 are different, I don't want DeepDiff to consider it.
diff = DeepDiff(object1, object2, excludePath)
The sample object looks like below:
Obj1:
{
"KEY1": "VALUE1",
"KEY2": "VALUE2",
"KEY3": "VALUE3",
"KEY4": 4,
"KEY5": [
{
"KEY6": "VALUE",
"KEY7": 6,
"KEY8": VALUE
}
]
}
You can use exclude_regex_paths and pass a regex or a set or list of path regexes to exclude.
In your case:
>>> DeepDiff(object1, object2, exclude_regex_paths=r"\['KEY[78]'\]")
More details on exclude-regex-paths in the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With