I'm not familiar with JavaScript and Axios, so any help will be great :)
My request from Axios to URL has this response.
data: '{"id":"test1", "cool":"test2"}'
When trying JSON.parse like this
const buildArray = (await axios(config)).data
let toJSON = JSON.parse(buildArray)
It gives me an error
Unexpected token in JSON at position 0
Here it is my code and what I'm trying to do. For each Axios data response I want to add it to an array item and return it.
async function buildList(items, token){
try {
const list = []
let config = ''
for (item of items.items) {
config = {
method: 'get',
url: 'https://my.domain.com/v1/customers/' + item.id,
headers: {
'Authorization': 'Bearer ' + token,
'Accept': 'application/json'
}
}
const buildArray = (await axios(config)).data
list.push(JSON.parse(buildArray))
}
return list
} catch (err) {
throw Error ('buildList error: ', err.message)
}
}
const buildArray = (await axios(config)).data
but as per the result you have shared you can parse it and it works here codepen.io/Maniraj_Murugan/pen/LYGrPXW .. – Maniraj Murugan