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
Body:
The json module currently serializes special floating-point values such as NaN, Infinity, and -Infinity as unquoted identifiers when allow_nan=True, which is non-standard JSON. While this behavior is useful in some contexts, there is currently no built-in way to override how these values are serialized when using json.dumps() or json.encoder.JSONEncoder.
Use Case:
Some applications may need to emit null, a fixed numeric value (like 0), or a quoted string (e.g., "NaN") instead of the default NaN, Infinity, and -Infinity. This is particularly important when interoperating with systems expecting strict or customized JSON.
Proposal:
Introduce a way to override the serialization of these special float values via a floatstr parameter, enabling developers to supply a callable that determines how to stringify such values.
Code of floatstr will not change, but it would be moved to the class, therefore it would allow the function to be overriten with custom value for NaN, infinite and -infinite.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
Body:
The json module currently serializes special floating-point values such as NaN, Infinity, and -Infinity as unquoted identifiers when allow_nan=True, which is non-standard JSON. While this behavior is useful in some contexts, there is currently no built-in way to override how these values are serialized when using json.dumps() or json.encoder.JSONEncoder.
Use Case:
Some applications may need to emit null, a fixed numeric value (like 0), or a quoted string (e.g., "NaN") instead of the default NaN, Infinity, and -Infinity. This is particularly important when interoperating with systems expecting strict or customized JSON.
Proposal:
Introduce a way to override the serialization of these special float values via a floatstr parameter, enabling developers to supply a callable that determines how to stringify such values.
Code of floatstr will not change, but it would be moved to the class, therefore it would allow the function to be overriten with custom value for NaN, infinite and -infinite.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: