On 14/09/2020 17:36, Christopher Barker
wrote:
nstructions that are not part of the JSON spec) but the proposed
new functions will be strict.
as it looks like I maybe the one to write the PR -- no, I'm not suggesting any changes to compliance.
The only thing even remotely on the table is only supporting UTF-8 -- but IIUC, the current functions, if they do the encoding/decoding for you, are already UTF-8 only, so no change.
load() and dump() work with text file-like objects -- they are not doing any encoding/decoding.
loads() is working with strings or bytes. if strings, then no encoding. if bytes, then:
"The ``encoding`` argument is ignored and deprecated since Python 3.1"
which I figured meant utf-8 but it fact it seems to work with utf-16 as well.
In [17]: utf16 = '{"this": 5}'.encode('utf-16')
In [18]: json.loads(utf16)
Out[18]: {'this': 5}
which surprises me. I'll need to look at the code and see what it's doing. Unless someone wants to tell us :-)
dumps(), meanwhile, dumps a str, so gain, no encoding.
The idea here is that if you want to use loadf() or dumpf(), it will be utf-8, and if you want to use another encoding, you can open the file yourself and use load() or dump()
--
Christopher Barker, PhD
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython