Skip to content

PEP 837: Extensible JSON serialization#5031

Open
serhiy-storchaka wants to merge 10 commits into
python:mainfrom
serhiy-storchaka:pep-837-extensible-json
Open

PEP 837: Extensible JSON serialization#5031
serhiy-storchaka wants to merge 10 commits into
python:mainfrom
serhiy-storchaka:pep-837-extensible-json

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 12, 2026

Copy link
Copy Markdown
Member

New PEP proposing an extension mechanism for the json encoder at
three levels: the __json__()/__raw_json__() protocol (library
level), a copyreg.json() registry following the copyreg.pickle()
precedent (application level), and a per-encoder dispatch_table
attribute mirroring pickle.Pickler (call level).

Reference implementation: python/cpython branch json-customize4
(link: https://github.com/serhiy-storchaka/cpython/tree/json-customize4).

The idea has been discussed repeatedly since 2010; see the PEP's
Motivation for the tracker issues and the python-ideas /
discuss.python.org threads:
2010,
2019,
2020,
2022 (registry),
2022–2024 (__json__).

Basic requirements (all PEP Types)

  • Read and followed PEP 1 & PEP 12
  • File created from the latest PEP template
  • PEP has next available number, & set in filename (pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) and PEP header
  • Title clearly, accurately and concisely describes the content in 79 characters or less
  • Core dev/PEP editor listed as Author or Sponsor, and formally confirmed their approval
  • Author, Status (Draft), Type and Created headers filled out correctly
  • PEP-Delegate, Topic, Requires and Replaces headers completed if appropriate (none applicable)
  • Required sections included
    • Abstract (first section)
    • Copyright (last section; exact wording from template required)
  • Code is well-formatted (PEP 7/PEP 8) and is in code blocks, with the right lexer names if non-Python
  • PEP builds with no warnings, pre-commit checks pass and content displays as intended in the rendered HTML
  • Authors/sponsor added to .github/CODEOWNERS for the PEP

Standards Track requirements

  • PEP topic discussed in a suitable venue with general agreement that a PEP is appropriate
  • Suggested sections included (unless not applicable)
    • Motivation
    • Specification
    • Rationale
    • Backwards Compatibility
    • Security Implications
    • How to Teach This
    • Reference Implementation
    • Rejected Ideas
    • Open Issues

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Jul 12, 2026

Copy link
Copy Markdown

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Discussion thread: https://discuss.python.org/t/pep-837-extensible-json-serialization/108124 (Discussions-To and Post-History headers added).

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I probably won't have time for a full review due to EuroPython, here's a couple of suggestions.

Comment thread peps/pep-0837.rst
Discussions-To: https://discuss.python.org/t/pep-837-extensible-json-serialization/108124
Status: Draft
Type: Standards Track
Created: 11-Jul-2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Created: 11-Jul-2026
Created: 12-Jul-2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wrote it 11-Jul-2026, but submitted next morning 12-Jul-2026. What counts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's the day the PEP number is assigned.

Sometimes PEPs are written months ago and iterated upon before a PR is opened and a number assigned.

Comment thread peps/pep-0837.rst Outdated
Comment thread peps/pep-0837.rst Outdated
Comment thread peps/pep-0837.rst Outdated
serhiy-storchaka and others added 2 commits July 12, 2026 12:47
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Also fix the markup of the '__raw_json__ as a pure marker' bullet
(inline markup cannot be nested) and escape numpy.bool_ in the
appendix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Thank you. Fixed rendering and modernized cpython-issue references.

serhiy-storchaka and others added 2 commits July 16, 2026 22:10
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka changed the title PEP 837: Extensible JSON serialization PEP 841: Extensible JSON serialization Jul 16, 2026
PEP 837 was freed for this PEP's earlier claim when the conflicting
PEP was renumbered to 840 in python#5043.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka changed the title PEP 841: Extensible JSON serialization PEP 837: Extensible JSON serialization Jul 16, 2026
serhiy-storchaka and others added 2 commits July 16, 2026 22:28

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved with date change, thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants