https://github.com/python/cpython/commit/b426caa04b1e165d4054125e67ee6c74141910a4 commit: b426caa04b1e165d4054125e67ee6c74141910a4 branch: main author: Gaurav Yadav <[email protected]> committer: nedbat <[email protected]> date: 2026-09-21T06:42:50-04:00 summary:
gh-157571: Move json sort note from dumps to dump (#157577) * gh-157571: Move json sort note from dumps to dump Signed-off-by: MeGaurav4 <[email protected]> * "coerce" is not a Python term. Co-authored-by: Ned Batchelder <[email protected]> --------- Signed-off-by: MeGaurav4 <[email protected]> Co-authored-by: Ned Batchelder <[email protected]> files: M Doc/library/json.rst diff --git a/Doc/library/json.rst b/Doc/library/json.rst index ddd12a002f7416..0d115c5623fd7d 100644 --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -234,6 +234,16 @@ Basic Usage If ``True``, dictionaries will be outputted sorted by key. Default ``False``. + .. note:: + + Keys in key/value pairs of JSON are always of the type :class:`str`. When + a dictionary is converted into JSON, all the keys of the dictionary are + converted to strings. As a result of this, if a dictionary is converted + into JSON and then back into a dictionary, the dictionary may not equal + the original one. That is, ``loads(dumps(x)) != x`` if x has non-string + keys. *sort_keys* sorts the keys before they are converted to strings, + so numeric keys are sorted by value, not by their string representation. + .. versionchanged:: 3.2 Allow strings for *indent* in addition to integers. @@ -253,17 +263,6 @@ Basic Usage table <py-to-json-table>`. The arguments have the same meaning as in :func:`dump`. - .. note:: - - Keys in key/value pairs of JSON are always of the type :class:`str`. When - a dictionary is converted into JSON, all the keys of the dictionary are - coerced to strings. As a result of this, if a dictionary is converted - into JSON and then back into a dictionary, the dictionary may not equal - the original one. That is, ``loads(dumps(x)) != x`` if x has non-string - keys. - *sort_keys* sorts the keys before they are coerced to strings, - so numeric keys are sorted by value, not by their string representation. - .. function:: load(fp, *, cls=None, object_hook=None, parse_float=None, \ parse_int=None, parse_constant=None, \ object_pairs_hook=None, array_hook=None, **kw) _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
