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

298
Views
NodeJS & Typescript - Unexpected end of JSON input

I am using Node.js and Typescript to get the data from rest api. I am alway getting an error unexpected end of JSON input. Whats wrong with my code?

I have stringify my code and with http requester it is working.

My json input looks like:

 {"json-input":{"handler":"getContent","image":true,"video":false,"text":false,"source":"1","lage":"testlage1"}}

My code

api.post("/getData", (req: Request, res: any, next: NextFunction) => {
    let getDataUrl = "restapiexample/?async";
    console.log(getDataUrl)


      let filter_data:any ={}
      delete req.body['keyId'];
      filter_data['json-input'] = req.body;

      let jsstringData = JSON.stringify(filter_data);
    console.log('###################################')
      console.log(jsstringData)
    console.log('###################################')

    request.post(
        {
            url : getDataUrl,
            form:jsstringData,
            headers : {
                "Authorization" : auth
            }
        },
        function (error, response, body) {
          if (error){
            console.log("There was an error:", error);
          } else {
            console.log("Request posted successfully!", JSON.parse(body));
          }


            // res.send(jsonData.jobs[0].id)
        }
    );
    });

Error

SyntaxError: Unexpected end of JSON input [1] at Object.parse (native) [1] at Request._callback (/home/tony/Desktop/ng2KnimeUI/dist/server/routes/api.js:49:62) [1] at Request.self.callback (/home/tony/Desktop/ng2KnimeUI/node_modules/request/request.js:188:22) [1] at emitTwo (events.js:106:13) [1] at Request.emit (events.js:191:7) [1] at Request. (/home/tony/Desktop/ng2KnimeUI/node_modules/request/request.js:1171:10) [1] at emitOne (events.js:96:13) [1] at Request.emit (events.js:188:7) [1] at IncomingMessage. (/home/tony/Desktop/ng2KnimeUI/node_modules/request/request.js:1091:12) [1] at IncomingMessage.g (events.js:291:16)

over 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!