[New-bugs-announce] [issue4785] json.JSONDecoder() strict argument undocumented and potentially confusing
David M. Beazley
report at bugs.python.org
Tue Dec 30 18:42:14 CET 2008
New submission from David M. Beazley <beazley at users.sourceforge.net>:
The strict parameter to JSONDecoder() is undocumented and is confusing
because someone might assume it has something to do with the encoding
parameter or the general handling of parsing errors (which it doesn't).
As far as I can determine by reading the source, strict determines
whether or not JSON strings are allowed to contain literal newlines in
them or not. For example (note: loads() passes its parameters to
JSONDecoder):
>>> s = '{"test":"Hello\nWorld"}'
>>> print(s)
{"test":"Hello
World"}
>>> json.loads(s)
Traceback (most recent call last):
...
File "/tmp/lib/python3.0/json/decoder.py", line 159, in JSONString
return scanstring(match.string, match.end(), encoding, strict)
ValueError: Invalid control character at: line 1 column 14 (char 14)
>>> json.loads(s,strict=False)
{'test': 'Hello\nWorld'}
>>>
Note in this last example how the result has the literal newline
embedded in it when strict is set False.
----------
assignee: georg.brandl
components: Documentation
messages: 78550
nosy: beazley, georg.brandl
severity: normal
status: open
title: json.JSONDecoder() strict argument undocumented and potentially confusing
type: behavior
versions: Python 2.6, Python 3.0
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4785>
_______________________________________
More information about the New-bugs-announce
mailing list