title: Handling application/json data with bottle
body: <p>I'm trying to write a simple server frontend to a python3 application, using a restful JSON-based protocol. So far, <a href="http://bottlepy.org" rel="nofollow">bottle</a> seems the best suited framework for the task (it supports python3, handles method dispatching in a nice way, and easily returns JSON.) The problem is parsing the JSON in the input request.</p>
  
  <p>The documentation only mention <code>request.fields</code> and <code>request.files</code>, both I assume refer to multipart/form-data data. No mention of accessing the request data directly.</p>
  
  <p>Peeking at the source code, I can see a <code>request.body</code> object of type BytesIO. <code>json.load</code> refuses to act on it directly, dying in the json lib with <code>can't use a string pattern on a bytes-like object</code>. The proper way to do it may be to first decode the bytes to unicode characters, according to whichever charset was specified in the <code>Content-Type</code> HTTP header. I don't know how to do that; I can see a StringIO class and assume it may hold a buffer of characters instead of bytes, but see no way of decoding a BytesIO to a StringIO, if this is even possible at all.</p>
  
  <p>Of course, it may also be possible to read the BytesIO object into a bytestring, then decode it into a string before passing it to the JSON decoder, but if I understand correctly, that breaks the nice buffering behavior of the whole thing.</p>
  
  <p>Or is there any better way to do it ?</p>