Lines Matching full:json

1 r"""JSON (JavaScript Object Notation) <https://json.org> is a subset of
5 :mod:`json` exposes an API familiar to users of the standard library
11 >>> import json
12 >>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
14 >>> print(json.dumps("\"foo\bar"))
16 >>> print(json.dumps('\u1234'))
18 >>> print(json.dumps('\\'))
20 >>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
24 >>> json.dump(['streaming API'], io)
30 >>> import json
32 >>> json.dumps([1,2,3,mydict], separators=(',', ':'))
37 >>> import json
38 >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4))
44 Decoding JSON::
46 >>> import json
48 >>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]') == obj
50 >>> json.loads('"\\"foo\\bar"') == '"foo\x08ar'
54 >>> json.load(io)[0] == 'streaming API'
57 Specializing JSON object decoding::
59 >>> import json
65 >>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
69 >>> json.loads('1.1', parse_float=Decimal) == Decimal('1.1')
72 Specializing JSON object encoding::
74 >>> import json
79 ... f'is not JSON serializable')
81 >>> json.dumps(2 + 1j, default=encode_complex)
83 >>> json.JSONEncoder(default=encode_complex).encode(2 + 1j)
85 >>> ''.join(json.JSONEncoder(default=encode_complex).iterencode(2 + 1j))
89 Using json.tool from the shell to validate and pretty-print::
91 $ echo '{"json":"obj"}' | python -m json.tool
93 "json": "obj"
95 $ echo '{ 1.2:3.4}' | python -m json.tool
123 """Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
132 ``obj``. Otherwise, all such characters are escaped in JSON strings.
140 in strict compliance of the JSON specification, instead of using the
143 If ``indent`` is a non-negative integer, then JSON array elements and
150 ``(',', ': ')`` otherwise. To get the most compact JSON representation,
186 """Serialize ``obj`` to a JSON formatted ``str``.
194 such characters are escaped in JSON strings.
202 strict compliance of the JSON specification, instead of using the
205 If ``indent`` is a non-negative integer, then JSON array elements and
212 ``(',', ': ')`` otherwise. To get the most compact JSON representation,
277 a JSON document) to a Python object.
282 can be used to implement custom decoders (e.g. JSON-RPC class hinting).
302 containing a JSON document) to a Python object.
307 can be used to implement custom decoders (e.g. JSON-RPC class hinting).
316 of every JSON float to be decoded. By default this is equivalent to
318 for JSON floats (e.g. decimal.Decimal).
321 of every JSON int to be decoded. By default this is equivalent to
323 for JSON integers (e.g. float).
327 This can be used to raise an exception if invalid JSON numbers
339 raise TypeError(f'the JSON object must be str, bytes or bytearray, '