Skip to content

Honor explicit ensure_ascii options in JSON output - #339

Open
fhgffy wants to merge 1 commit into
cdgriffith:developfrom
fhgffy:fix-20261011-json-ensure-ascii
Open

fhgffy wants to merge 1 commit into
cdgriffith:developfrom
fhgffy:fix-20261011-json-ensure-ascii

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 10, 2026

Copy link
Copy Markdown

Passing ensure_ascii to Box.to_json() or BoxList.to_json() currently raises TypeError: json.dumps() got multiple values for keyword argument 'ensure_ascii'. The shared converter supplies the option explicitly while also forwarding it from json_kwargs. File output has the same problem through json.dump().

Set ensure_ascii=False only when the caller has not provided it. This preserves the existing Unicode output by default and allows callers to request escaped ASCII JSON. It also covers the existing multiline file-output path.

The tests check exact serialized text and round-trip values for both public classes, strings and files, explicit true/false and the unchanged default, Unicode keys/values and emoji, ASCII file encoding, multiline files, and other JSON options. Includes the changelog and contributor entries requested by CONTRIBUTING.rst; targets develop.

Validation on Linux / CPython 3.12.14:

  • Unchanged base: 159 tests passed in pure Python and with Cython extensions.
  • New regression selection on the unchanged runtime: 11 failed, 5 passed in each mode.
  • Fixed full suite: 175 tests passed in pure Python and with freshly rebuilt Cython 3.3.0 extensions.
  • black --check --config=.black.toml box test setup.py (24.10.0): passed.
  • mypy box (1.13.0): passed, eight source files.
  • CC=gcc python setup.py build_ext --inplace -j 2 and git diff --check: passed.

Optional test dependencies were installed from the project requirements. Other Python versions and operating systems were not run locally.

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.

1 participant