Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
nodejs request body as json

I have the following curl:

curl 'http://localhost:9008/updated' \ 
  -H 'Connection: keep-alive' \
  -H 'Accept: application/json, text/plain, /' \ 
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36' \ 
  -H 'Content-Type: application/x-www-form-urlencoded' \ 
  -H 'Accept-Language: es-ES,es;q=0.9' \ 
  -data-raw '{"data":[{"id":"12345"}]}'

In NodeJS, I receive the req.body as an object:

{ '{"data":[{"id":"12345"}]}' }

but I should receive as a JSON like in the curl:

{"data":[{"id":"12345"}]}

This is my handler:

router.post('/updated', express.json(), function (req, res) {
   logger.info(req.body) // output as object, and It should be a JSON
});

Any ideas to remove the extra { or receive a JSON like in the curl?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try changing Content-Type: application/x-www-form-urlencoded to Content-Type: application/json in your curl command

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!