-
-
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
base: main
Are you sure you want to change the base?
Conversation
…bility of key type coercion limitation in json module docs
Please do not use the Update Branch button unless necessary (e.g. fixing conflicts, jogging the CI, or very old PRs) as it uses valuable resources. For more information see the devguide. |
Thanks for StanFromIreland's suggestion Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Doc/library/json.rst
Outdated
For Example, | ||
``json.loads('{"42":"value"}')`` returns the dictionary | ||
``{'42': 'value'}``. |
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.
I don't totally see how this example is related to the note. I think it's fine to just have the two sentences without the example.
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.
hmmm.this note is for beginners,they may think loads JSON text like {"42":"spam"}
will get {42:'spam'}
yes,i made a silly mistake and wasted some CI resource
function:: loads()
to Improve visibility…function:: loads()
to Improve visibility…
function:: loads()
to Improve visibility…json.loads
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Now I have added note in the module-level documentation,need we nuke the notes under |
Doc/library/json.rst
Outdated
@@ -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. | |||
|
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.
Doc/library/json.rst
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
You can link the RFC as it was done previously.
Now I am thinking whether putting this note above "Basic Usage" Part is suitable |
Doc/library/json.rst
Outdated
@@ -146,6 +146,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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is too long and we have now three places where this kind of mention occurs. Here, in json.dumps() and in json.loads(). Let's avoid three different formulations and let's do as follows:
- Remove the new note in json.loads().
- Remove the note in json.dumps() and move it here (you can start this note by "RFC ... requires JSON keys to be strings".
- You can add an example for json.dumps() and json.loads() which shows what happens when we dump or load something with an numeric python key.
Doc/library/json.rst
Outdated
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. | ||
The encoder will convert all non-string keys in dictionaries into string, |
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.
Remove the note in json.dumps()
We're stil lacking the:
I wanted you to remove the redundant part, not the entire part, sorry if I was unclear. We may also avoid using a note and just write it directly in the text. I'm leaving this afternoon so I won't be able to shepherd this. |
TIP: Partially fixes gh-137533, do not close the issue
📚 Documentation preview 📚: https://cpython-previews--137545.org.readthedocs.build/