I should probably start a FAQ for questions like this that keep coming
up (and I'd welcome suggestions on how and where to explain things
like this).
request.arguments and the methods that work with it (get_argument,
get_arguments, decode_argument) are designed around the limitations
and peculiarities of the x-www-form-encoded format (technically a
multimap but typically used as a map, underspecified character
encodings, etc). If you weren't saddled with that format to begin
with, why try to fit your relatively expressive json data into its
constraints?
Just do something like this, and then use self.json_args.get("foo")
instead of self.get_argument("foo"):
def prepare(self):
if self.request.headers.get("Content-Type") == "application/json":
self.json_args = json_decode(self.request.body)
Note that when initialize() runs it's too early to send a proper error
page, so it should only be used for very simple code that can't really
fail. prepare() is a better place to do things like this.
-Ben