Skip to content

Instantly share code, notes, and snippets.

@appikonda
Created April 13, 2020 18:49
Show Gist options
  • Save appikonda/e9b2d452e79a8a25fe627477d189bb08 to your computer and use it in GitHub Desktop.
Save appikonda/e9b2d452e79a8a25fe627477d189bb08 to your computer and use it in GitHub Desktop.
adding element to json
import json
# a Python object (dict):
x = [{
"name": "John",
"age": 30,
"city": "New York"
},
{
"name": "sandeep",
"age": 30,
"city": "Walnut Creek"
}]
x.insert(0,{"averageAge":30, "firstCity ": "newYork"})
# convert into JSON:
y = json.dumps(x)
# the result is a JSON string:
print(y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment