deepdiff
deepdiff copied to clipboard
Ignoring order for deeply nested lists of dictionaries.
Is your feature request related to a problem? Please describe. I have a dataset that looks like:
{
"_links": {
"self": {
"href": "/accounts/036aa770-b6fe-11ed-b489-b625a1e46b37/messages"
}
},
"_embedded": {
"messages": [
{
"id": "c589614c-b6cb-11ed-9083-7cb91a971123",
"channel": "email",
"contact": {},
"status": "delivered",
},
{
"id": "c5892790-b6cb-11ed-8a7c-a8944afb6fba",
"channel": "email",
"contact": {},
"status": "delivered"
}
]
}
}
I'd like group_by to work with deep lists such as this.
Describe the solution you'd like
Calling like DeepDiff(old, new, ignore_order=True, group_by={"root['_embedded']['messages']": "id"}) would be able to apply different grouping to different areas in the dataset.
Describe alternatives you've considered I'll just have to manipulate my data myself prior to comparison. The disadvantage of this is that I don't get a diff that reflects the level of nesting of the list.
Hi @explorigin
This is going to be tricky. It seems like you want to diff at the "root['_embedded']['messages']" level. Then group by id.
So what happens to the rest of the items in your nested dictionary that don't fall under "root['_embedded']['messages']" ?
I'd like to convert the list at "root['_embedded']['messages']" to an object keyed by id and then diff the whole data tree.
@explorigin Ah, I see. Ok, that makes more sense than what I mentioned above. I'm curious if this is a very common use case or not.
It's common for me. :-) The example is a common REST API reply where you have a result and some metadata in one package.
We now allow group_by to take 2 elements. In your case, it needs to take 3.
I think we should make group_by take arbitrary number of elements.