Message78550
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. |
|
Date |
User |
Action |
Args |
2008-12-30 17:42:14 | beazley | set | recipients:
+ beazley, georg.brandl |
2008-12-30 17:42:14 | beazley | set | messageid: <1230658934.34.0.991784557371.issue4785@psf.upfronthosting.co.za> |
2008-12-30 17:42:13 | beazley | link | issue4785 messages |
2008-12-30 17:42:13 | beazley | create | |
|