Skip to content

Fix JSON encoding of native Python values in Ion containers - #451

Open
Pybsama wants to merge 1 commit into
amazon-ion:masterfrom
Pybsama:codex/fix-ion-json-native-values
Open

Pybsama wants to merge 1 commit into
amazon-ion:masterfrom
Pybsama:codex/fix-ion-json-native-values

Conversation

@Pybsama

@Pybsama Pybsama commented Sep 24, 2026

Copy link
Copy Markdown

Issue #, if available:

Fixes #163

Description of changes:

Convert Ion containers to plain containers without eagerly calling default() on each child. The existing JSON encoder then handles native Python values normally and dispatches nested Ion values through the existing Ion-specific conversions.

This fixes the reported case of adding a native string to a loaded Ion struct, as well as native values in Ion lists and s-expressions. The struct conversion retains its existing keys() / o[key] behavior for duplicate fields.

Regression coverage includes native scalars and containers, alternating native/Ion nesting, special Ion values, native non-finite floats and allow_nan, dictionary keys and skipkeys, unsupported values, duplicate fields, input preservation, and circular references. The production change is limited to the two container conversion expressions.

Validation

  • New tests against the previous implementation: 101 failed for the expected serialization/circular-reference errors; 32 existing or preservation-control cases passed.
  • pytest -q tests/test_json_encoder.py: 133 passed on CPython 3.9.6 (pure Python), 3.12.13 (C extension), and 3.14.6 (pure Python).
  • Default non-benchmark suite, using the same exclusions as the project configuration:
    • CPython 3.12.13 with the source-built C extension: 29,286 passed, 1 skipped.
    • CPython 3.9.6 pure Python: 29,323 passed, 5 skipped.
  • Both full-suite runs reported the same 10 existing enum/record deprecation warnings. Skips follow the existing backend/version conditions. Benchmark tests and other operating systems were not run.
  • git diff --check passed.

Implementation and local review were assisted by OpenAI Codex.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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.

IonToJSONEncoder does not correctly handle native Python types

1 participant