On this page
json.loads
Prev: json.load | Up: json
Rel: json.dump, json.dumps, json.JSONDecodeError, json.JSONDecoder
Ref: docs.python.org — json.loads
Tags: #public #python3 #stdlib #json
Import
import json
from json import loads
Signature & Overview
json.loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
Deserialize s (a str, bytes or bytearray instance containing a JSON document) to a Python object.
Usage
import json
from decimal import Decimal
obj = json.loads('{"price": 19.99, "tags": ["a", "b"]}', parse_float=Decimal)
assert obj["price"] == Decimal("19.99")
assert obj["tags"] == ["a", "b"]
Gotchas
- Accepts
str,bytes, orbytearray: UTF-8/16/32 bytes are decoded automatically. - No trailing commas or comments: Standard JSON rejects
//comments, single quotes, and trailing commas withJSONDecodeError. NaN/Infinityaccepted by default: Passparse_constant=raisingValueErrorif you need strict RFC 8259 compliance.
REPL Inspect
from json import loads
help(loads)
Linked from
Related notes
- tuts/python3/stdlib_module/json/load Linked here; links to this page; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/json/dump Linked here; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json/dumps Linked here; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json/JSONDecodeError Linked here; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json/JSONDecoder Linked here; shared tags: #json, #stdlib
- tuts/python3/stdlib_module/json/JSONEncoder shared tags: #json, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib