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 ?