Skip to content

Instantly share code, notes, and snippets.

@PoplarYang
Created March 25, 2019 10:49
Show Gist options
  • Save PoplarYang/449ff435d58912b684bdaa7e84ba1257 to your computer and use it in GitHub Desktop.
Save PoplarYang/449ff435d58912b684bdaa7e84ba1257 to your computer and use it in GitHub Desktop.
usage for json module
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