I’m trying to get data out of a reply given to me from a backend API. I have an object called result
which contains the following reply from the server:
{
connection: 'Keep-Alive',
'content-language': 'en-GB',
'content-length': '0',
'content-type': 'text/html'
date: 'Fri, 11 Mar 2022 06:41:06 GMT',
'keep-alive': 'timeout=5, max=100',
}
I’m trying to get the ‘keep-alive’ part but I’m unsure how I can access it.
I’ve tried parsing result
as JSON
const obj = JSON.parse(result)
console.log(obj)
But this throws the following error:
undefined:1
[object Object]
^
SyntaxError: Unexpected token o in JSON at position 1
The issue seems to be that connection and date aren’t within single quotes and I don’t know how to fix this.