At the moment python_parse parses JSON floats to python floats (internally an f64 AFAIK), thereby potentially loosing some information.
(I guess JsonValue arguably suffers from the same problem as it parses floats to rust's f64)
The idea would be to create a new JsonFloat Rust struct that implemented pyclass (so it's available as an option in Python), internally JsonFloat would just hold a string representing the original JSON float data, but have the following signature in python:
class JsonFloat:
def as_decimal(self) -> Decimal:
"""Construct a Decimal directly from the original string"""
# what do we do about scientific notation?
def as_float(self) -> float:
"""Use the current logic to parse the string as a float at call time"""
def __str__(self) -> str:
"""Return the original string"""
PythonParser should be generic in FloatParser so there's no overhead if you want normal float as now.
In future we could do something similar for JsonValue if needed, but that doesn't have to happen at the same time.
At the moment
python_parse
parses JSON floats to python floats (internally an f64 AFAIK), thereby potentially loosing some information.(I guess
JsonValue
arguably suffers from the same problem as it parses floats to rust'sf64
)The idea would be to create a new
JsonFloat
Rust struct that implemented pyclass (so it's available as an option in Python), internallyJsonFloat
would just hold a string representing the original JSON float data, but have the following signature in python:PythonParser
should be generic inFloatParser
so there's no overhead if you want normalfloat
as now.In future we could do something similar for
JsonValue
if needed, but that doesn't have to happen at the same time.