json.JSONDecoder()
json.JSONDecoder() is a Python function in the JSON Module category. Extensible JSON decoder for custom deserialization. The syntax is json.JSONDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None). Returns: Decoder instance. A typical example: def as_datetime(dct):
if "timestamp" in dct:
dct["timestamp"] = datetime.fromisoformat(dct["timestamp"])
return dct
data = json.loads(json_str, object_hook=as_datetime). A close sibling is json.dumps(), which serializes a Python object to a JSON formatted string. A close sibling is json.loads(), which deserializes a JSON string to a Python object. A close sibling is json.dump(), which serializes a Python object to a JSON formatted stream (file). A close sibling is json.load(), which deserializes a JSON formatted stream (file) to a Python object. More about this category: JSON encoding and decoding — dump, load, dumps, loads. For a broader walkthrough, read the JSON Module guide. Related JSON Module entries: json.dumps(), json.loads(), json.dump(), json.load(), json.JSONEncoder().