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

152
Views
Can't parse JSON from POST request using express in react

I'm having a problem parsing my JSON request using express, and after many hours of trying to research it, I can't figure out what the problem is. Here is my code snippet

app.post('/Information', (req, res)=> {
    console.log(req.body); // this prints out the exact POST request from Postman
    const info = JSON.parse(req.body); // this returns SyntaxError: Unexpected token o in JSON at position 1
    let insertQuery = `insert into Information(id, name, number, message) 
                       values(${info.id}, '${info.name}', '${info.number}', '${info.message}')`

    client.query(insertQuery, (err, result)=>{
        if(!err){
            res.send('Insertion was successful')
        }
        else{ console.log(err.message) }
    })
    client.end;
})

I know the reason behind the parsing error, trying to parse an 'o', because req.body is an object, but I tried the three methods of accessing properties of an object, and I get 'undefined'. I don't know if this will help, but if I send this POST request { "id":"3", "name":"Mark Zuckerberg", "number":"1112223333", "message":"Welcome to Facebook!" } from Postman, then this is what console.log(req.body) will print out {'{\r\n "id":"3",\r\n "name":"Mark Zuckerberg",\r\n "number":"1112223333",\r\n "message":"Welcome to Facebook!"\r\n}\r\n': ''}. This output looks odd to me because of the (: '') at the end, as it makes it look like there are only 2 properties for some reason and I don't understand why that's happening. I would be glad to try out any ideas you guys have, because I'm really lost right now. Thank you in advance.

about 4 years ago · Santiago Trujillo
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!