Full-stack web applications developer

Loading posted JSON

April 24, 2014Arthur Pemberton0 Comments

If you’re using jQuery, and have an entire JSON document document that you would like to post to Django, the correct way to do it is not through a separate variable, but by posting the actual JSON.

To post the entire JSON string, without any other parameters:

    data: JSON.stringify(response),
    type: 'POST'

In your view, when receiving the post data, you can convert the posted JSON string into Python dictionary:

# load Decimal class
from decimal import Decimal
# load json library from stdlib
import json
# load entire post body as json (using Decimal for floating point numbers)
data = json.loads(request.body, parse_float=Decimal)

Leave a Reply