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

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

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 Report

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 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!