I want to merged two json data, which I did. Please see the python code and json data below.
json_data
[
{
"fields": {
"Full Address": "data1",
"hz": "text1",
"ot": "doc1"
}
},
{
"fields": {
"Full Address": "data2",
"hz": "text2",
"ot": "doc2"
}
}
]
json_data1
[
{
"fields": {
"Full Address": "data2",
"hz": "text2",
"ot": "doc2"
}
},
{
"fields": {
"Full Address": "data3",
"hz": "text3",
"ot": "doc3"
}
}
]
Result_merged_json
[
{
"fields": {
"Full Address": "data1",
"hz": "text1",
"ot": "doc1"
}
},
{
"fields": {
"Full Address": "data2",
"hz": "text2",
"ot": "doc2"
}
},
{
"fields": {
"Full Address": "data2",
"hz": "text2",
"ot": "doc2"
}
},
{
"fields": {
"Full Address": "data3",
"hz": "text3",
"ot": "doc3"
}
}
]
Python_code
import json
import io
with open("json1.json") as f1:
data = json.load(f1)
with open("json2.json") as f2:
data1 = json.load(f2)
data.extend(data1)
with io.open('Result_merged_json.json', 'w', encoding='utf8') as f3:
data = json.dumps(data, indent=2, ensure_ascii=False)
f3.write(data)
Here in the result: "Full Address": "data2" along with the other values comes two time. But I want one time in my Result_merged_json. I tried to do some changing in code, but I could not get result as per my choice. So how could I preventing from copying the data?
{
"fields": {
"Full Address": "data2",
"hz": "text2",
"ot": "doc2"
}
}