I have the following data in my c.json file:
{
"192.168.0.129": {
"username": "me",
"streaming": "Spotify",
"name": "John",
"email": "[email protected]"
}
}
and this other data that I want to append it to:
new_data = {'next_songs': ['song1', 'song2']}
for that purpose I'm doing this:
with open('c.json', 'r') as json_data:
data = json.load(json_data)
data.update(new_data)
with open('c.json', 'w') as json_data:
json.dump(data, json_data, indent=4)
this works, but no quite, because I get:
{
"next_songs": [
"song1",
"song2"
],
"192.168.0.129": {
"username": "me",
"streaming": "Spotify",
"name": "John",
"email": "[email protected]"
}
}
and I want appended data to be a value under the key "192.168.0.129", like so:
{
"192.168.0.129": {
"username": "me",
"streaming": "Spotify",
"name": "John",
"email": "[email protected]"
"new_data": ["song1", "song2"],
}
}
how do I achieve this?