[New-bugs-announce] [issue30114] json module: it is not possible to override 'true', 'false' values during encoding bool

Marian Horban report at bugs.python.org
Thu Apr 20 06:04:06 EDT 2017


New submission from Marian Horban:

It is not possible to override 'true', 'false' values during encoding bool.
For example if I want to dump dict like:
    {"key": True}
and result must be not 
    {"key": true}
but let's say
    {"key": "TRUE"}
It is really hard to force json.dumps function to do it.

I understand that improving of json encoder performance causes this inflexible implementation.
Perfect solution for extending/overriding json module would be move nested functions
_iterencode_list
_iterencode_dict
_iterencode
into class JSONEncoder as static methods.
But it could make performance a bit worse.

So if we cannot afford it I would propose to move function _make_iterencode to JSONEncoder as a static method.
This change will not degrade performance.
But it will be possible to override this method in SPECIFIC user's Encoder.

----------
components: Library (Lib)
files: json_improvement.patch
keywords: patch
messages: 291959
nosy: Marian Horban 2
priority: normal
severity: normal
status: open
title: json module: it is not possible to override 'true', 'false' values during encoding bool
type: enhancement
versions: Python 2.7
Added file: http://bugs.python.org/file46816/json_improvement.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30114>
_______________________________________


More information about the New-bugs-announce mailing list