Some Python Examples
← prev | next →     Top-level ToC     /json.html     (printable version)

You load from json to Python.
You dump from Python to json.

import json

# Returns a Python data structure.
vals = json.loads(open('foo.json').read())

data = {
    'name': 'Za',
    'size': 3,
    'age': 1.4,
}

s = json.dumps(data) # Returns a string containing json.

Note, re json vs Python:

null <==> None
true <==> True
false <==> False

About json:

  • strings go in double-quotes only
  • no comments in .json files
  • no trailing commas
  • top-level object is usually a dict