I'm working with the below code.
- I'm trying to reach a JSON file, and fetch some data.
- Pass it to render() function and convert to Javascript Object.
Promise.all(STATUS_CODES.map((status) => {
const url = `https://${domainName}/api/v2/search/tickets?query="status:${status}"`;
return client.request.get(url, options);
})).then((responses) => { render(responses); }) // [1] Function invoked here
.catch((err) => {
showError('API request(s) failed.');
console.error('API request(s) failed.', err);
});
}
function render(responses) {
/** Convert JSON String into Javascript Object */
const data = responses.map(r => JSON.parse(r.response)); // [2] Confused with this line
const max = Math.max(...data.map(d => d.total));
The problem that I need help with is in this line
const data = responses.map(r => JSON.parse(r.response));
Here is some data that I fetch the JSON at ${status} = 2: https://codebeautify.org/online-json-editor/cb535226
Problem
When [1] is invoked, and the JSON string is sent as a parameter to [2] to parse in JS Object. But, in the statement r.response, I expect there has to be a response property in the JSON. But I'm not able to find it if I manually search for it.
However in the next line d.total, I'm able to find total property.
The Complete code works just as fine as expected, but I want to understand how does it work if response property is not there in the JSON String?