Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
randomir opened this issue Mar 2, 2017 · 0 comments
Open

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

randomir opened this issue Mar 2, 2017 · 0 comments

Comments

@randomir
Copy link

randomir commented Mar 2, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant