I'm trying to update test.json file with a Python script. I only need to change the property of "plan2"->"2"->"rooms" to 3. Could you please help me with this?
Thank you very much
test.json
{
"plan1" : [{
"1": {
"rooms":"2",
"bathrooms":"1",
"kitchens":"1"
},
"2": {
"rooms":"1",
"bathrooms":"1",
"kitchens":"1"
}
}],
"plan2":[{
"1": {
"rooms":"3",
"bathrooms":"1",
"kitchens":"1"
},
"2": {
"rooms":"1",
"bathrooms":"1",
"kitchens":"1"
}
}]
}
test.py
import json
with open("test.json", "r+") as jsonFile:
data = json.load(jsonFile)
# need to change the "plan2"->"apartments"->"2"->"rooms" to 3
jsonFile.seek(0) # rewind
json.dump(data, jsonFile)
jsonFile.truncate()