Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda