Skip to content

FR: opt-in strict=False-style leniency for control chars in strings (default behavior unchanged)Β #152

Description

@bukzor

TL;DR: opt-in flag to accept unescaped control chars (e.g. a bare newline)
inside strings, mirroring stdlib json's strict= β€” default behavior and
spec-compliance untouched. I'll write it; just want a πŸ‘/πŸ‘Ž before I sink
time in. No reply needed either way: a πŸ‘, or silence past ~2 weeks, I'll
take as a green light to send a small draft PR (loads() only,
strict=True default) for you to review whenever's convenient. An explicit
comment is a stop sign. Feel free to just close this if it's not wanted.

Why: pyjson5.loads('"foo\nbar"') (a literal newline byte, not the
two-char \n escape) raises Json5EOF. I know 1.4.7 made this rejection
deliberate, "per spec" β€” not disputing that default. My case: real files
from a shipping system whose own runtime parses them as-is, bare newlines
included β€” not malformed/legacy data, just not spec-pure JSON5.

Why this stays out of your compliance/correctness/security bar:

  • Default unchanged β€” new kwarg defaults to today's strict behavior, so the
    "all valid JSON5/JSON can be read" guarantee is untouched.
  • Decode-only β€” encode_*() and its HTML-safety escaping are untouched.
  • Documented as an explicit spec deviation when enabled, same caveat stdlib
    json gives for its strict flag.
  • Precedent: the pure-Python json5 package (dpranke's, on PyPI as
    json5) already has this exact strict kwarg/semantics β€” matching an
    existing convention, not inventing one.

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