I am looking to merge two JSON strings into one in Python. string1 has identical Keys as string2, but string2 has several values in a list, like the example below:
string1:
{'Target': 'DEV1', 'Supplier': '0', 'Message': 'A', 'Name': 'Supp1'}
string2:
{'Target': ['DEV2', 'DEV3'], 'Supplier': ['1', '2'], 'Message': ['B', 'C'], 'Name': ['Supp2', 'Supp3']}
Hopeful Merged Output string3:
{'Target': ['DEV1', 'DEV2', 'DEV3'], 'Supplier': ['0', '1', '2'], 'Message': ['A', 'B', 'C'], 'Name': ['Supp1', 'Supp2', 'Supp3']}
I'm not too familiar with JSON, but here's my current position:
import json
str1 = json.loads(string1)
str2 = json.loads(string2)
string3 = {key, val for (key, val) in (str1.items() and str2.items())
The last line I found in Stackoverflow for merging JSON strings, but I am struggling with the list appending for each value.
Any help would be greatly appreciated.
printfor the three strings?Value? What's supposed to be the output?