Issue 31466: No easy way to change float formatting when subclassing encoder.JSONEncoder (original) (raw)

Created on 2017-09-14 09:48 by qpeter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3515 closed qpeter,2017-09-14 09:49
Messages (4)
msg302162 - (view) Author: Quentin Peter (qpeter) * Date: 2017-09-14 09:48
I want to output floats in ENG format. Working with distance in micrometers, it is a bit annoying to see: 2.5e-5 .0003 instead of 25e-6 300e-6 The solution I found was to redefine `iterencode` but that doesn't feel right. I would like to see something similar to the "default" function that is easely modified.
msg302306 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2017-09-16 00:44
Hello and thanks for the patch! If you don’t get feedback, you could try the python-ideas mailing list to see if other people have the same need and if there’s already a solution for this. Serhiy, would you mind refreshing my memory about json development? I’m not sure whether it’s still supposed to follow the development of simplejson, or if it’s effectively a fork now.
msg387891 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-03-02 01:09
May I close this? There is no discussion in python-dev/python-ideas. I feel that this proposal is too minor. Stdlib shouldn't add option for such minor use case.
msg389993 - (view) Author: Samuel Freilich (sfreilich) * Date: 2021-04-01 15:16
I think the less-minor issue, of which this is a small subset, is that JSONEncoder doesn't allow changing the behavior for default-serializable types at all. That means you can't choose to lose less information in round-trip serialization/deserialization, if that's what you want (e.g. there's no way to round-trip serialize a tuple with JSONEncoder, though it's trivial to do that for a set).
History
Date User Action Args
2022-04-11 14:58:52 admin set github: 75647
2021-04-01 15:16:16 sfreilich set nosy: + sfreilichmessages: +
2021-03-08 04:04:28 methane set status: open -> closedresolution: rejectedstage: patch review -> resolved
2021-03-02 01:09:12 methane set nosy: + methanemessages: +
2019-03-26 23:21:39 cheryl.sabella set versions: + Python 3.7, Python 3.8, - Python 3.6
2017-09-16 00:44:34 eric.araujo set nosy: + serhiy.storchakamessages: +
2017-09-15 18:01:24 eric.araujo set nosy: + eric.araujo
2017-09-14 09:49:31 qpeter set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest3561>
2017-09-14 09:48:13 qpeter create