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

112
Visualizações
How to access the below object parameters in Javascript
output = "{\"response\":200,\"message\":\"Id: 123 updated successfully\"}{\"response\":403,\"message\":\"Receipt with Id: 124 not updated\"}"

How to access the response on the above output? Unable to convert to json due to invalid format

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The output you have is almost valid, you could put the two objects into an array and walk through them to check for the key value 'response' and for example print the values like so:

output = [{"response":200,"message":"Id: 123 updated successfully"},
          {"response":403,"message":"Receipt with Id: 124 not updated"}];
for(let i=0; i<output.length; i++){
  if(output[i].hasOwnProperty('response')){
      console.log(output[i]['response']);
   }
 }

Output:

200
403

Please note the '[]' brackets put around the response objects returned to make the variable 'output' iterable.

about 4 years ago · Juan Pablo Isaza Relatório

0

try the following:

output = `{"response":200,"message":"Id: 123 updated successfully"}{"response":403,"message":"Receipt with Id: 124 not updated"}`
output = output.replaceAll("}", "},");
output = output.substring(0, output.length - 1);
output = "[" + output  + "]"

console.log(output)
console.log(JSON.parse(output) )

about 4 years ago · Juan Pablo Isaza Relatório
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