Skip to content

Lossless numeric option for JsonValue parsing to preserve Decimal #230

@CasperKristiansson

Description

@CasperKristiansson

When using JsonValue::parse_with_config, fractional JSON numbers are parsed into Float(f64), so the original literal is lost. Downstream (e.g., pydantic-core’s JsonValidator path) cannot build a Decimal from the original text and only sees f64.to_string(), causing precision loss.

Ask: add an opt‑in mode on the JsonValue parsing path that preserves the raw numeric token (e.g., a lossless number variant or raw text) so consumers can construct Decimal without going through f64.

References:

  • crates/jiter/src/value.rs: JsonValue enum currently uses Float(f64) for fractional numbers.
  • pydantic-core invokes JsonValue::parse_with_config in pydantic-core/src/validators/json.rs::JsonValidator.
  • Related pydantic issue: Decoding Decimal from JSON number is lossy pydantic#9180 (Decimal precision loss when parsing JSON numbers via JsonValue).

Context: Workarounds are parsing via PythonParse with FloatMode::Decimal or passing numbers as strings. An opt‑in lossless JsonValue mode would let pydantic-core keep its existing pipeline while preserving precision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions