Json data not reaching Django properly
<p>In my project, the frontend is in Angular2, 
I'm making a POST request to a Django url like this:</p>

<pre><code>let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let body = JSON.stringify(this.myMetadata);
let req = this.http.post(this.url,body,options)
  .map((res:Response) =&gt; res.json())
  .subscribe(
    data =&gt; { this.response = data},
    err =&gt; console.error(err),
    () =&gt; console.log('done')
  );
  return req;
</code></pre>

<p>But the Django backend is not receving the data as JSON</p>

<pre><code>if request.method == 'POST':
    logger.info(request.method)
    logger.info(type(request.body))
    logger.info(request.POST)
</code></pre>

<p>log dumps show that Django has received the data as string, due to this none of the json methods work on it.</p>

<pre><code>Method:POST
request.body type:&lt;type 'str'&gt;
</code></pre>

<p>What is the best way to resolve this?</p>

<p>is there a way to convert a string to a dictionary?</p>

<blockquote>
  <p>Is there a way to convert a string to a dictionary?</p>
</blockquote>

<p>Yes just use the json module</p>

<pre><code>import json
...
if request.method == 'POST':
    data = json.loads(request.body)
    logger.info(type(data))
</code></pre>

python json django