I have 3 json files with differen key pair values and all files reside in same directory. I need to merge/append all 3 json into single json file which will be used to some frontend application usage
Example files I have:
File 1:
[
{
"Key": "Region",
"Value": "US"
},
{
"Key": "Zone",
"Value": "1"
}
]
File 2:
[
{
"Drive": "/dev/sdb",
"Size(GB)": "20",
"Encrypted": true
}
]
File 3:
[
{
"AlarmName": "Test",
"StateValue": "OK"
}
]
Output expected single json:
[
{
"Key": "Region",
"Value": "US"
},
{
"Key": "Zone",
"Value": "1"
},
{
"Drive": "/dev/sdb",
"Size(GB)": "20",
"Encrypted": true
},
{
"AlarmName": "Test",
"StateValue": "OK"
}
]
can some one suggest or any reference specific reference for this
EDIT 1:
Tried some suggestion in python below:
import json
f1data = f2data = f3data = ""
with open(f'C:\csv\file1.json') as f1:
f1data = f1.read()
with open(f'C:\csv\file2.json') as f2:
f2data = f2.read()
with open(f'C:\csv\file3.json') as f3:
f3data = f3.read()
f1data += "\n"
f1data += f2data
f2data += f3data
with open ('C:\csv\combined.json', 'w') as f3:
f4.write(f1data)
its erroring out
OSError: [Errno 22] Invalid argument: 'C:\\csv\file3.json'