Because you seem to want to keep some values and overwrite others, I have hastily cobbled together a recursive function that does that, barring some edge-cases.
def combine(dict1, dict2):
"""Updates dict1 to contain dict2"""
for key in dict2:
if key in dict1:
if isinstance(dict1[key], list): # If value is a list, we want special logic
if isinstance(dict2[key], list): # if the "input" is a list, just do list + list
dict1[key] = dict1[key] + dict2[key]
else:
dict1[key].append(dict2[key])
elif isinstance(dict1[key], dict): # calling itself recursively
dict1[key] = combine(dict1[key], dict2[key])
else: # Overwrites all other values
dict1[key] = dict2[key]
else: # Creates the values that doesn't exist.
dict1[key] = dict2[key]
return dict1
It's a mess and nigh unreadable. Anyway, here is a demonstration:
import json
json1 = '{ "key": {"a": "1", "b": "2", "c": "3", "list": ["5", "6", "7"] } }'
json2 = '{ "key": {"b": "9", "list": ["8"] } }'
json1 = json.loads(json1)
json2 = json.loads(json2)
print(json1) # {'key': {'a': '1', 'b': '2', 'c': '3', 'list': ['5', '6', '7']}}
print(json2) # {'key': {'b': '9', 'list': ['8']}}
print(combine(json1,json2)) # {'key': {'a': '1', 'b': '9', 'c': '3', 'list': ['5', '6', '7', '8']}}