8000 gh-134150: Clarify distinction between JSON and Python objects (#134154) · python/cpython@fa4e088 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa4e088

Browse files
authored
gh-134150: Clarify distinction between JSON and Python objects (#134154)
* gh-134150: Clarify distinction between JSON objects and Python objects in json module docs * Revert change to JSON introduction * Clarify occurrences of "object literal" as JSON
1 parent 009e7b3 commit fa4e088

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Doc/library/json.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ is a lightweight data interchange format inspired by
1818
`JavaScript <https://en.wikipedia.org/wiki/JavaScript>`_ object literal syntax
1919
(although it is not a strict subset of JavaScript [#rfc-errata]_ ).
2020

21+
.. note::
22+
The term "object" in the context of JSON processing in Python can be
23+
ambiguous. All values in Python are objects. In JSON, an object refers to
24+
any data wrapped in curly braces, similar to a Python dictionary.
25+
2126
.. warning::
2227
Be cautious when parsing JSON data from untrusted sources. A malicious
2328
JSON string may cause the decoder to consume considerable CPU and memory
2429
resources. Limiting the size of data to be parsed is recommended.
2530

26-
:mod:`json` exposes an API familiar to users of the standard library
31+
This module exposes an API familiar to users of the standard library
2732
:mod:`marshal` and :mod:`pickle` modules.
2833

2934
Encoding basic Python object hierarchies::
@@ -60,7 +65,7 @@ Pretty printing::
6065
"6": 7
6166
}
6267

63-
Specializing JSON object encoding::
68+
Customizing JSON object encoding::
6469

6570
>>> import json
6671
>>> def custom_json(obj):
@@ -83,7 +88,7 @@ Decoding JSON::
8388
>>> json.load(io)
8489
['streaming API']
8590

86-
Specializing JSON object decoding::
91+
Customizing JSON object decoding::
8792

8893
>>> import json
8994
>>> def as_complex(dct):
@@ -279,7 +284,7 @@ Basic Usage
279284

280285
:param object_hook:
281286
If set, a function that is called with the result of
282-
any object literal decoded (a :class:`dict`).
287+
any JSON object literal decoded (a :class:`dict`).
283288
The return value of this function will be used
284289
instead of the :class:`dict`.
285290
This feature can be used to implement custom decoders,
@@ -289,7 +294,7 @@ Basic Usage
289294

290295
:param object_pairs_hook:
291296
If set, a function that is called with the result of
292-
any object literal decoded with an ordered list of pairs.
297+
any JSON object literal decoded with an ordered list of pairs.
293298
The return value of this function will be used
294299
instead of the :class:`dict`.
295300
This feature can be used to implement custom decoders.

0 commit comments

Comments
 (0)
0