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

185
Views
assign json model to in javascript

I want to send a request to another API to get list of currency prices.

 https.get(this.baseUrl, (response) => {
                response.on('data', async (chunk) => {
                model = JSON.parse(JSON.stringify(chunk.toString('utf-8')));
      })
   });

response :

    {
      "success":true,
      "timestamp":1641994743,
      "base":"EUR",
      "date":"2022-01-12",
      "rates":{
        "AED":4.184454,
        "AFN":120.094117,
        "ALL":122.214122,
        "AMD":548.537072,
        "ANG":2.052899,
        "AOA":609.048742
         }
    }

I got array buffer and I use this command to convert that to a string model :

chunk.toString('utf-8')

when I use JSON.parse(chunk.toString('utf-8')) it show me this error :

UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input

and when I want to use this code :

model = JSON.parse(JSON.stringify(chunk.toString('utf-8')));

I can not access to model property . for example I an not access to model.success or model['success'] it show me undefined.

now whats the problem ? how can I solve this problem ?

about 4 years ago · Juan Pablo Isaza
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!