Created
April 13, 2020 18:49
-
-
Save appikonda/e9b2d452e79a8a25fe627477d189bb08 to your computer and use it in GitHub Desktop.
adding element to json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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