I'm trying to merge two json files each of them contain an array of objects, here is an example of how the data looks line in each file:
data in file 1:
[{"tag": "MODL", "entity": "QX50"}, {"tag": "MODL", "entity": "QX60"}, {"tag": "MODL", "entity": "QX70"}]
data in file 2:
[{"tag": "MANF","entity": "لكزس"},{"tag": "MANF","entity": "جيب"},{"tag": "MANF","entity": "هونداي"}]
so I tried to merge them by this code:
import json
f1data = f2data = ""
with open('merged_file_models_arabic.json') as f1:
f1data = f1.read()
with open('MANF_arabic.json') as f2:
f2data = f2.read()
f1data += "\n"
f1data += f2data
with open ('merged_MANF_MODL.json', 'a') as f3:
f3.write(f1data)
but the result in 'merged_MANF_MODL.json' file becomes two arrays, and this is not what I want, I want the two arrays in each file merged into one array in 'merged_MANF_MODL.json' file.
Expected result:
[{"tag": "MODL", "entity": "QX50"}, {"tag": "MODL", "entity": "QX60"}, {"tag": "MODL", "entity": "QX70"}, {"tag": "MANF","entity": "لكزس"},{"tag": "MANF","entity": "جيب"},{"tag": "MANF","entity": "هونداي"}]