I have 2 dictionaries in python (d1, d2) where I need to pass the missing "id" item from d2 to d1, ignoring any other differences (such as the extra "child" in d1). What effectively is needed, is that a result dictionary is just d1 with "id" items added. I have tried merging, but it did not work since either way I lose data.
d1 = {
"parent": {
"name": "Axl",
"surname": "Doe",
"children": [
{
"name": "John",
"surname": "Doe"
},
{
"name": "Jane",
"surname": "Doe",
"children": [
{
"name": "Jim",
"surname": "Doe"
},
{
"name": "Kim",
"surname": "Doe"
}
]
}
]
}
}
d2 = {
"parent": {
"id": 1,
"name": "Axl",
"surname": "Doe",
"children": [
{
"id": 2,
"name": "John",
"surname": "Doe"
},
{
"id": 3,
"name": "Jane",
"surname": "Doe",
"children": [
{
"id": 4,
"name": "Jim",
"surname": "Doe"
},
{
"id": 5,
"name": "Kim",
"surname": "Doe"
},
{
"id": 6
"name": "Bill",
"surname": "Doe"
},
]
}
]
}
}
result = {
"parent": {
"id": 1,
"name": "Axl",
"surname": "Doe",
"children": [
{
"id": 2,
"name": "John",
"surname": "Doe"
},
{
"id": 3,
"name": "Jane",
"surname": "Doe",
"children": [
{
"id": 4,
"name": "Jim",
"surname": "Doe"
},
{
"id": 5,
"name": "Kim",
"surname": "Doe"
}
]
}
]
}
}
Any ideas?