Skip to content

Comments

Improve json API compatibility and preserve core type fidelity#97

Open
danielendler wants to merge 4 commits intomainfrom
codex/assess-and-process-feedback-for-datason-v2.0.0a1
Open

Improve json API compatibility and preserve core type fidelity#97
danielendler wants to merge 4 commits intomainfrom
codex/assess-and-process-feedback-for-datason-v2.0.0a1

Conversation

@danielendler
Copy link
Owner

Motivation

  • Close gaps in the advertised "drop-in" behavior for json.dumps/json.loads by accepting common stdlib arguments and validating unknown kwargs.
  • Preserve collection type fidelity (especially tuple, set, frozenset) when type hints are enabled so round-trips do not lose identity.
  • Normalize float special-value string output and fix timezone-naive datetime round-trips for UNIX/UNIX_MS modes to avoid surprising semantics.

Description

  • Split dumps/dump kwargs into Datason config overrides and allowed json.dumps kwargs, passing through accepted JSON options like indent, ensure_ascii, skipkeys, separators, and default, while applying config defaults when not provided (datason/_core.py).
  • Emit built-in Datason metadata for tuple, set, and frozenset when include_type_hints=True and restore those types on loads, while preserving legacy list output when hints are disabled (datason/_core.py, datason/_deserialize.py).
  • Canonicalize NanHandling.STRING outputs to "NaN", "Infinity", and "-Infinity" instead of lowercased strings (datason/_core.py).
  • Preserve timezone-naive datetime semantics for DateFormat.UNIX/UNIX_MS by emitting a small dict containing a timestamp and naive marker and restoring a naive datetime when appropriate (datason/plugins/datetime.py).
  • Accept and forward common json.loads/json.load parsing kwargs (parse_float, parse_int, object_hook, etc.) and validate unknown kwargs with clear TypeError messages (datason/_deserialize.py).
  • Added and updated unit tests to cover JSON-compat arguments, collection round-trips, NaN string casing, and naive UNIX_MS datetime behavior (tests/unit/test_core.py, tests/unit/test_plugin_datetime.py).

Testing

  • Ran the full test suite with uv run pytest -q, resulting in 272 passed, 15 skipped and no failures.
  • Ran targeted test runs uv run pytest tests/unit/test_core.py tests/unit/test_plugin_datetime.py tests/unit/test_deserialize.py -q which passed successfully.
  • Ran linter checks with uv run ruff check datason tests which produced no issues.
  • New and updated unit tests exercise dumps/dump JSON kwargs handling, loads kwargs, collection type fidelity, NaN string normalization, and naive datetime UNIX/UNIX_MS round-trips and passed in CI-local runs.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant