Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
Javascript JSON not parsing properly

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.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda