You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The standard library's json.loads function includes a parse_float hook. If configured, this will be called for any floating point number with the raw input str. This may be used to parse all float values as decimal.Decimal types by passing parse_float=decimal.Decimal.
We might want to support an option like this. Due to msgspec's design, we'd probably go with:
Calling the option float_hook to mirror the other callback names
If configured this would be called to decode any float value that didn't have an explicit type configured (e.g. type=Any only). This would effectively let the user configure how untyped float values are decoded - float values with specified output types wouldn't use this mechanism.
To parse all untyped floats as decimals you'd do something like msgspec.json.decode(msg, float_hook=decimal.Decimal).
The text was updated successfully, but these errors were encountered:
Description
The standard library's
json.loads
function includes aparse_float
hook. If configured, this will be called for any floating point number with the raw input str. This may be used to parse all float values asdecimal.Decimal
types by passingparse_float=decimal.Decimal
.We might want to support an option like this. Due to msgspec's design, we'd probably go with:
float_hook
to mirror the other callback namestype=Any
only). This would effectively let the user configure how untyped float values are decoded - float values with specified output types wouldn't use this mechanism.To parse all untyped floats as decimals you'd do something like
msgspec.json.decode(msg, float_hook=decimal.Decimal)
.The text was updated successfully, but these errors were encountered: