Skip to content

Custom serialization of non-finite (inf/nan) floats #159

Description

@randomir

It would be great to be able to handle serialization of non JSON serializable floats (the non-finites: inf, -inf, nan). Preferably, in a manner consistent with the existing mechanisms for serialization of non-JSON types -- the user-supplied default function.

Something like:

>>> simplejson.dumps(float('inf'), allow_nan=False, default=lambda x: {"$repr": repr(x)})
'{"$repr": "inf"}'

If you think this would be worthwhile, I'm willing to work on a pull request (I submitted a first draft Python-only implementation, let me know if you agree with the direction).

Btw, this issue is tangential to #149, which can be addressed similarly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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