title: http.server: decoding POST request to JSON
body: <p>i'm writing a very simple http-server based on <code>http.server</code> (using Python-3)</p>
  
  <p>the client is supposed to send a json-object via POST.</p>
  
  <pre><code>payload={'text': 'bi ba buzemann!',
           'nouns': ['streetlight', 'situation'],
           'states': ['solid', 'fluid']
          }
  requests.post(url, data=payload)
  </code></pre>
  
  <p>this arrives fine at the server, but in a serializd form</p>
  
  <pre><code>def do_POST(self:
    length = self.headers['content-length']
    data = self.rfile.read(int(length))
    # b'states=solid&amp;states=fluid&amp;nouns=oracle&amp;text=bi+ba+buzemann%21'
  </code></pre>
  
  <p>now my question is: how do i turn this urlencoded result back into a dict (or the intermediate JSON)?</p>
  
  <p>do i have to do this manually, as in:</p>
  
  <pre><code>for x in str(r).split('&amp;'):
     y,z=x.split('=')
     if not y in d:
        d[y]=[]
     d[y]+=[urllib.parse.unquote_plus(z)]
  </code></pre>
  
  <p>or is there some well-debugged function available in some common module?</p>