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

189
Views
How to remove unwated characters from api response

I am creating api in NodeJS in api response I am getting / this characters Below is my api response:

img

 static async getAdminOrders(logId, callback) {
  
  logger(logId, `Getting all orders of the stylist ${logId}`);
  const queryStr = 'SELECT order_details FROM stylist_order';
  Util.executeQuery(queryStr,logId).then((result) => {
  callback(false, result || [], Util.statusCodes.SUCCESS);
  
  var str = JSON.stringify(result);

  // Remove \ from the string
  var str1 = str.replace(/\\/g,'');

  // Convert updated string back to object
  var newObj = JSON.parse(str1);
  console.log(newObj);

}).catch((error) => {
  logger(logId, error);
  callback(true, { message: 'Failed to fetch order detials' }, Util.statusCodes.INTERNAL_SERVER_ERROR);
});
}

It is not returning object back after removing unwanted characters in console but when I am doing console.log(str1) its returning string without /. Issue is newObj is not showing.

Someone let me know what I am doing wrong.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The backslash escapes the " character, so they are not really unwanted. When you just remove them, you could potentially damage the payload, since JSON.parse() can't read the string properly anymore. I would instead try to parse the data string itself like this:

static async getAdminOrders(logId, callback) {
  
  logger(logId, `Getting all orders of the stylist ${logId}`);
  const queryStr = 'SELECT order_details FROM stylist_order';
  Util.executeQuery(queryStr,logId).then((result) => {
  callback(false, result || [], Util.statusCodes.SUCCESS);
  
  for(let i = 0; i < result.data; i++){
    result.data[i].order_details = JSON.parse(result.data[i].order_details)
  }
  
  console.log(result);

}).catch((error) => {
  logger(logId, error);
  callback(true, { message: 'Failed to fetch order detials' }, Util.statusCodes.INTERNAL_SERVER_ERROR);
});
}
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!