Skip to content

Pure Python JSON decoder reports the error position one character past an invalid escape #162028

Closed

Description

@thejesh23

Bug report

Bug description:

For an invalid \escape in a string, the pure Python decoder reports the position of the character after the backslash. The C decoder reports the position of the backslash.

from test.support import import_helper

cjson = import_helper.import_fresh_module("json", fresh=["_json"])
pyjson = import_helper.import_fresh_module("json", blocked=["_json"])

for json in cjson, pyjson:
    try:
        json.loads('"\\a"')
    except ValueError as e:
        print(e.pos)
# C: 1
# Python: 2

This is the same kind of difference that gh-154936 fixed for control characters.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 15, 2026
  2. added a commit that references this issue on Nov 16, 2026
  3. added 2 commits that reference this issue on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions