I am trying to update,add key,value pairs of dict into JSON File.
JSON File- hi.json
{
"site_post": {
"site_name":"test site",
"location" : "test location",
"latitude": "123.23",
"longitude": "456.23"
},
"plant_post": {
"plant_name" : "plant test",
"site_id" : "",
"plant_id": ""
}
}
import json
with open('hi.json') as f:
data = json.load(f)
dct = {"site_id":"123","plant_id":"456"}
Expected Output- hi.json
{
"site_post": {
"site_name":"test site",
"location" : "test location",
"latitude": "123.23",
"longitude": "456.23",
"site_id" : "123"
},
"plant_post": {
"plant_name" : "plant test",
"site_id" : "123",
"plant_id": "456"
}
}
I checked using below posts, but didn't find expected ans. Ref link-