Ember: jQuery Post with nested JSON-Payload

Marc M

I want to POST some JSON to my REST-Server.

The JSON looks like that:

  {
    "name": "John Doe",
    "socials": {
      "facebook": {
        "uid": "1234321",
        "fbsrCookie": "sdfsdfhgsd"
      }
    }
  }

The POST-Call in Ember looks like that:

Ember.$.post('http://localhost:3000/register', data).then(function ...

Inspecting the Message with the Developer-Tools of Firefox show me that the parameters are the following

name: "John Doe"
socials[facebook][uid]: "1234321"
socials[facebook][fbsrCookie]: "sdfsdfhgsd"

Because of the Header "Content-Type" which is "application/x-www-form-urlencoded; charset=UTF-8" I cant handle with the values as objects on my node.js-backend (since its not JSON).

Is there a way a to read the properties from the server-(node.js)-backend? Or how can I send the payload as JSON?

Marc M

Okay, like @sdgluck mentioned, the express.js-Framework (which Im using) can also parse the form-data (url-encoded)parameters decribed in my question above. So I double checked the including of the bodyParser-middleware of express.js and changed the "extended"-Parameter to true like so:

app.use(bodyParser.urlencoded({
  extended: true
}));

Now express.js also parse the parameters and let me access them via dot-notation (like so: req.body.socials.facebook.uid).

Thanks to @sdgluck !

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Ember-data RESTAdapter without JSON payload

Nested json payload and nested array javascript interview

Ember Rails 'POST' Nested Route

Response to json Payload in POST API not in Json Format

Map a nested JSON payload to a struct in Elixir

How to deal with dynamic nested json payload?

How to send JSON payload as body in POST in AFMotion

Making a POST request using puppeteer with JSON payload

How to POST a JSON payload to a @RequestParam in Spring MVC

GZip JSON payload in GoLang before POST

Create a json payload in Go Lang POST request?

POST request to REST API with JSON object as payload

How to post data as json from request payload?

Using CURL POST with Json format payload

Ember Data: Using "links" on JSON payload for hasMany relationships

Convert custom json payload to something Ember Data understands?

Error when passing a Python nested dictionary as a payload for POST call

post request with nested json

POST nested Json with Silex

Add payload in Ember deleteRecord

How to access raw json payload from remote service in Ember when using Ember-data?

how to handle nested json responses with ember?

Ember.js / Rails Nested JSON

PUT request with JSON payload sent from Postman, nested object not parsed

How to remove specific elements from a nested JSON payload (JavaScript)?

Using Ember Data RestSerializer to POST to a 3rd-party API, how can I change the payload format?

Karate / Post Request : Unable to pass random generator variable in json payload

Golang: http.NewRequest POST with JSON payload returns error 500

Using Gin: How to pass original JSON payload to a Redirect POST