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

267
Visualizações
Find all ocurrences after specific string in another string

I have a response from an API (actually is a composite message from AWS lex) and it look like this:

 '{\"messages\":[{\"type\":\"PlainText\",\"group\":1,\"value\":\"Great!\"},{\"type\":\"PlainText\",\"group\":2,\"value\":\"Please click here.\"}]}'

I can't change the response to a string, and I need to get from that string the text of:

"Great!" and "Please click here."

Basically anything after => "value\":\" and before \"}

I have tried plenty of approaches but couldn't hit the nail. Is there any way to do this, I even tried writing a regex but what I could get was the string before and not the actual text I need.

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

0

We can use JSON.parse to convert your JSON API output to a JS object. Then, we can iterate all messages in the array and extract the values.

var input = '{\"messages\":[{\"type\":\"PlainText\",\"group\":1,\"value\":\"Great!\"},{\"type\":\"PlainText\",\"group\":2,\"value\":\"Please click here.\"}]}';
var x = JSON.parse(input);
var arr = x.messages.map(item => item.value)
console.log(arr);

about 4 years ago · Juan Pablo Isaza Relatório

0

Why won't you just use JSON.parse()?

const responseJson = '{"messages":[{"type":"PlainText","group":1,"value":"Great!"},{"type":"PlainText","group":2,"value":"Please click here."}]}';
const response = JSON.parse(responseJson);
const values = response.messages.map(message => message.value);

// values is now ['Great!', 'Please click here.']
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