Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!