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

  • Home
  • SEARCH
  • 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 7895221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:35:26+00:00 2026-06-03T07:35:26+00:00

I want to POST an Object via JSON to node.js server. The Object structure

  • 0

I want to POST an Object via JSON to node.js server.

The Object structure is nested, and never succeeded to receive and parse correctly on node.js server site.


EDIT2

I found a solution: see the answer section…


EDIT

I found

     console.log(body);

itself output

val1=hello&val2%5Bval3%5D=world

//= {“val1″:”hello”,”val2[val3]”:”world”}

weired JSON way


client.js

    var data ={val1:"hello",val2:{val3:"world"}};
    console.log(data); // -> *1
    $.ajax({
        url:"/",
        type:"POST",
        dataType: 'json',
        data:data,
        success:function (res)
        {
            resHandler(res);
        }
    });

*1 ChromeDevelopersTool

Object

val1: “hello”

val2: Object

val3: “world”


server.js

var onreq = function (req, res)
{
    if(req.method == 'POST')
    {
        var body = '';
        req.on('data', function (data)
        {
            body += data;
        });
        req.on('end', function ()
        {
            var json = qs.parse(body);
            console.log(json.val1); //hello
            console.log(json.val2); //undefined
            console.log(json.val3); //undefined

            console.log(JSON.stringify(json)); 
            //{"val1":"hello","val2[val3]":"world"}
        });
    }

I understand

val2[val3]
is
val2.val3

However,


Problem 1

JSON.stringify prints out

{“val1″:”hello”,”val2[val3]”:”world”}

not

{val1:”hello”,val2:{val3:”world”}}

It’s ugly, and I don’t know why it’s like that.


Problem 2

I can never get {val3:”world”}

console.log(json.val3); //undefined


Anyone can explain, and how can I POST a nested JSON to node.js server?

Thanks.

  • 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-03T07:35:27+00:00Added an answer on June 3, 2026 at 7:35 am

    Do NOT use JSON typed data on jQuery Ajax, instead use Stringified JSON

    I created a WIKI

    http://code.google.com/p/kenokabe/wiki/nestedJSONproblem

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

Sidebar

Related Questions

I have a scraping object basically. I want to be able to add POST
I want to post some data via javascript to another domain. Something like: http://www.othersite.com/submitfunnyname?name=blah
I want to invoke an ASP.NET web service via an http POST request using
From my view I am sending via $.ajax a JSON object to my controller
I have an XML object that I want to send to my player via
Happy coding weekend to everyone!!!. I'm stuck trying to send a JSON object via
I want to send a JSON object to a PHP file while my script
I have a collection of Post objects and I want to be able to
I want to post some values from a simple HTML form, validate them with
I want to post on twitter wall but don't want that user can edit

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.