defnull/bottle — Issue #277: parse json less strictly
Author: ads901119
Created: 2012-02-01 01:26:05+00:00
State: open

A standard and strict json format is
{"title": "\u6587\u7ae0\u6807\u9898\n\u6362\u884c"}

Sometimes, especially in a cross-language platform, the json would be
{"title": "Title
new line"}
Using simplejson.loads(json) might cause the exception to occur:

Traceback (most recent call last):
File "testjson.py", line 24, in
print simplejson.loads(json)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/PIL/__init__.py", line 384, in loads

File "build/bdist.macosx-10.5-i386/egg/simplejson/decoder.py", line 402,
in decode
File "build/bdist.macosx-10.5-i386/egg/simplejson/decoder.py", line 418,
in raw_decode
simplejson.decoder.JSONDecodeError: Invalid control character at: line 1
column 15 (char 15)

simplejson.loads() has a parameter that is not mentioned in the documentation, “strict”. With this parameter we can parse json string less strictly.

Therefore, is it possible for bottle to change its json parsing as some form like
simplejson.loads(json, strict=False)
and instead of "request.json['data']", is there a more elegant way?