Structured Data Modules

json

Serialize supported Python values to JSON text and parse JSON back into Python objects. Use dumps()/loads() for in-memory values and dump()/load() for streams. JSON object keys are strings; arbitrary Python objects do not round-trip unchanged. Bound untrusted input and use allow_nan=False when emitting strict JSON numbers.

Formal Syntax & Structure

python syntaxpython
import json

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import jsonrecord = {"name": "Ada", "active": True}encoded = json.dumps(record, sort_keys=True)print(encoded)print(json.loads(encoded)["active"])
Python Reference