-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-137533: document key type coercion limitations in json.loads
#137545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Rov-Waff
wants to merge
19
commits into
python:main
Choose a base branch
from
Rov-Waff:fix-issue-137533
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+29
−7
Open
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
98ba5d5
gh-137533:Add a note under `function:: loads()` to Improve visibility…
Rov-Waff dcfd3f3
Merge branch 'main' into fix-issue-137533
Rov-Waff 1161ad0
gh-137533:fix:warp line 396 to 6 lines
Rov-Waff 56dfcfd
gh-137533:add a link for RFC8259
Rov-Waff 40d0cd1
gh-137533:make up more example to explain json.loads
Rov-Waff 9b6732b
gh-137533:make up more example to explain json.loads
Rov-Waff 8c9d81b
gh-137533:just restate the key of json must be string
Rov-Waff 40c5678
gh-137533:restate that keys in JSON must be strings at module-level docs
Rov-Waff 541878a
gh-137533:add RFC link ,then fix a RFC link at line 376
Rov-Waff e0dc7eb
gh-137533:nuked new note under function:: loads()
Rov-Waff 1814bfa
gh-137533:shorten the sentence of this note,maybe its too short : (
Rov-Waff f17de69
gh-137533:correct expression
Rov-Waff a4b8240
gh-137533:move notes under json.dumps() to module-level documents
Rov-Waff 1a71527
gh-137533:fix the note in json.dump()
Rov-Waff da6e655
gh-137533:make a example in json.loads()
Rov-Waff 3d0b304
gh-137533:nuked notes in json.dumps() and json.loads()
Rov-Waff d61e84b
gh-137533:make a section about json key convertion,then make some ref
Rov-Waff 96f54a7
gh-137533:remove the notes above part basic usage
Rov-Waff 9bbdb5a
gh-137533:warp too long lines
Rov-Waff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ is a lightweight data interchange format inspired by | |
The term "object" in the context of JSON processing in Python can be | ||
ambiguous. All values in Python are objects. In JSON, an object refers to | ||
any data wrapped in curly braces, similar to a Python dictionary. | ||
|
||
.. warning:: | ||
Be cautious when parsing JSON data from untrusted sources. A malicious | ||
JSON string may cause the decoder to consume considerable CPU and memory | ||
|
@@ -146,6 +145,13 @@ See :ref:`json-commandline` for detailed documentation. | |
This module's encoders and decoders preserve input and output order by | ||
default. Order is only lost if the underlying containers are unordered. | ||
|
||
.. note:: | ||
According to RFC 7159, the keys of all objects in JSON are strings. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can link the RFC as it was done previously. |
||
Under normal circumstances,the encoder of this module | ||
will convert the keys of all Python dictionaries into strings as the | ||
keys of JSON objects, and the decoder of this module will | ||
decode the keys of all JSON objects into strings as the keys | ||
of Python dictionaries | ||
|
||
Basic Usage | ||
----------- | ||
|
@@ -364,6 +370,12 @@ Basic Usage | |
.. versionchanged:: 3.9 | ||
The keyword argument *encoding* has been removed. | ||
|
||
.. note:: | ||
StanFromIreland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
As mandated by :rfc:`8259`, JSON keys must be :class:`str` objects. | ||
In particular, ``json.loads('{"42": "spam"}')`` returns ``{'42': 'spam'}``, | ||
but ``json.loads('{42: "spam"}')`` fails since ``42`` is not a valid JSON key. | ||
|
||
|
||
Encoders and Decoders | ||
--------------------- | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please undo unrelated changes.