How to append key an item to .json file in Python?
(It is not necessary to have format {"Time": "Short"})
I have .json:
{
"random": [
{
"Volume": "Any",
"Light": "Bright"
}
]
}
I need to add one string "Time": "Short" to get:
"random": [
{
"Volume": "Any",
"Light": "Bright",
"Time": "Short"
}
]
}
What i did:
data = json.load(json_file)
data["req"].append({"Time": "Short"})
json.dump(data, json_file, indent=3)
And .json looks like:
{
"random": [
{
"Volume": "Any",
"Light": "Bright"
}
]
}
"random": [
{
"Volume": "Any",
"Light": "Bright",
"Time": "Short"
}
]
}