Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:05:17+00:00 2026-06-15T16:05:17+00:00

I am trying to figure out how to deal with POSTed json objects in

  • 0

I am trying to figure out how to deal with POSTed json objects in Django. I’m POSTing a json object to the server and want to use it like a python dictionary.

here is my js:

$.post(
        "/projects/vote/", 
        obj,
        function(data) {
            //alert("Data Loaded: " + data);
            alert(data["msg"]);
});

What I am returning (end of django view):

return HttpResponse(json.dumps(foo), mimetype="application/json")

where

foo = {"msg": str(postdata)}

In other words, I’m POSTing a json object to the server, and alerting the string of the python object I get on the server so I can see what’s going on.

If my obj is:

var obj = {
    'bulk': false,
    'data': {
          'chosen': '14',
          'proj1': '15',
          'proj2': '14',
          'proj3': '16',
          'more': false,


        },
    'data2': [
           {
               'a': 'apple'
           },
           {
               'b': 'banana'
           },
        ],      
  }

I get this in return:

<QueryDict: {u'data[proj3]': [u'16'], u'data[proj2]': [u'14'], u'data[chosen]': [u'14'], u'data[proj1]': [u'15'], u'bulk': [u'false'], u'data2[0][a]': [u'apple'], u'data[more]': [u'false'], u'data2[1][b]': [u'banana']}>

How come the structure of the json obj and python dict don’t align? And how do I get the structure to be the same? e.g. instead of data2[0][a], I would get data2 as the key to another dictionary

How I’m getting postdata:

# django version 1.4
postdata = request.POST.copy()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:05:17+00:00Added an answer on June 15, 2026 at 4:05 pm

    You may post json as plain string using JSON.stringify like this:

        $.post(
                "/projects/vote/", 
                {msg: JSON.stringify(obj)},
                function(data) {
                    //alert("Data Loaded: " + data);
                    alert(data);
        });
    

    Thus on server side you should just extract 'msg' from request.POST:

        def view(request):
              return HttpResponse(request.POST['msg'], mimetype="application/json")
    

    Note, that JSON.stringify is not supported by default in some browsers and you may want to use json lib: https://github.com/douglascrockford/JSON-js

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a great deal of difficulty trying to figure out the logic behind
Trying to figure out how I can do this properly. The print_r looks like
Trying to figure out which to use.
I'm trying to figure out the best way to deal with writing multiple GUI
I deal with a lot of print jobs and I'm trying to figure out
I am trying to figure out the proper way to use NSManagedObjectContexts when you
I'm trying to figure out how to deal with multiple uploads in FuelPHP. Basically
I'm trying to figure out what would be the best way to deal with
I've been trying to figure out the best way to deal with a footer
I'm trying to figure out how to draw a color map like this: http://www.ritsplasman.com/images/colormap.png

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.