This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: No easy way to change float formatting when subclassing encoder.JSONEncoder
Type: enhancement Stage: resolved
Components: Versions: Python 3.8, Python 3.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, methane, qpeter, serhiy.storchaka, sfreilich
Priority: normal Keywords: patch

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:
instead of 
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).
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75647
2021-04-01 15:16:16sfreilichsetnosy: + sfreilich
messages: + msg389993
2021-03-08 04:04:28methanesetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2021-03-02 01:09:12methanesetnosy: + methane
messages: + msg387891
2019-03-26 23:21:39cheryl.sabellasetversions: + Python 3.7, Python 3.8, - Python 3.6
2017-09-16 00:44:34eric.araujosetnosy: + serhiy.storchaka
messages: + msg302306
2017-09-15 18:01:24eric.araujosetnosy: + eric.araujo
2017-09-14 09:49:31qpetersetkeywords: + patch
stage: patch review
pull_requests: + pull_request3561
2017-09-14 09:48:13qpetercreate