Python json Module
Example
Serialize to JSON and back:
import json
data = {"name": "Emil", "age": 30}
s = json.dumps(data, sort_keys=True)
print(s)
print(json.loads(s)["name"])
Try it Yourself »
Definition and Usage
The json module encodes and decodes JSON (JavaScript Object Notation) data.
Use it to serialize Python objects to strings/files and to parse JSON back to Python data types.
Members
Member | Description |
---|---|
dump() | Serialize obj as a JSON formatted stream to a file-like object. |
dumps() | Serialize obj to a JSON formatted str. |
JSONDecoder | Class for customizing JSON deserialization (parsing) behavior. |
JSONEncoder | Class for customizing JSON serialization (encoding) behavior. |
load() | Deserialize fp (a .read()-supporting file-like object) to a Python object. |
loads() | Deserialize a str, bytes or bytearray instance containing a JSON document to a Python object. |