-
-
Save PoplarYang/449ff435d58912b684bdaa7e84ba1257 to your computer and use it in GitHub Desktop.
usage for json module
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 | |
# some JSON: | |
x = '{ "name":"John", "age":30, "city":"New York"}' | |
# parse x: | |
y = json.loads(x) | |
# the result is a Python dictionary: | |
print(y["age"]) | |
#----------------------------------------------------- | |
# a Python object (dict): | |
x = { | |
"name": "John", | |
"age": 30, | |
"city": "New York" | |
} | |
# 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