JSON
Some terminology:
when going from JSON → Python = “load”
when going from Python → JSON = “dump”
when going from Python → JSON = “dump”
import json
# Returns a Python data structure.
= json.loads(open('foo.json').read())
vals
= {
data 'name': 'Za',
'size': 3,
'age': 1.4,
}
= json.dumps(data) # Returns a string containing json. s
Note, re. JSON vs Python:
null ↔︎ None
true ↔︎ True
false ↔︎ False
true ↔︎ True
false ↔︎ False
About JSON:
- strings in double-quotes only
- no comments in .json files
- no trailing commas
- top-level object is usually a dict