Skip to content

Unquoted identifiers lose leading characters after numeric underscores #231

Closed

Description

@mfurkanakinci

Version of the library

0.63.4, also reproduced on main at 0a7317e.

Describe the bug

An unquoted identifier starting with digits loses leading characters if its numeric prefix contains underscores. Instead of only adding quotes, repair changes the identifier itself.

How to reproduce

from json_repair import repair_json

print(repair_json('{"sku": 123_456ABC}', return_objects=True))
# {'sku': '23_456ABC'}
print(repair_json('[1_2_3ABC]', return_objects=True))
# ['2_3ABC']

Expected behavior

The results should preserve 123_456ABC and 1_2_3ABC as strings. Pure numeric values such as 123_456 should continue to become 123456.

This affects the interaction between underscore normalization (#169) and the number-to-string fallback (#174). I plan to retain the original token position when falling back to string parsing and add regression tests.

A tested fix is available on fix/preserve-numeric-identifiers. This repository currently restricts PR creation to collaborators, so I could not open the corresponding upstream PR.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions