Skip to content
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

gh-132021: Add bool type to the list of allowed JSON key types #132048

Merged
merged 6 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/library/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ Encoders and Decoders
(to raise :exc:`TypeError`).

If *skipkeys* is false (the default), a :exc:`TypeError` will be raised when
trying to encode keys that are not :class:`str`, :class:`int`, :class:`float`
or ``None``. If *skipkeys* is true, such items are simply skipped.
trying to encode keys that are not :class:`bool`, :class:`str`, :class:`int`,
:class:`float` or ``None``. If *skipkeys* is true, such items are simply skipped.

If *ensure_ascii* is true (the default), the output is guaranteed to
have all incoming non-ASCII characters escaped. If *ensure_ascii* is
Expand Down
2 changes: 1 addition & 1 deletion Lib/json/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, *, skipkeys=False, ensure_ascii=True,
"""Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt
encoding of keys that are not str, int, float or None. If
encoding of keys that are not bool, str, int, float or None. If
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: json.dumps uses the order "str, int, float, bool, None" in its docstring and docs, so we might as well use the same order here for consistency

skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str
Expand Down
Loading