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

200
Visualizações
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 Respostas
Responde à pergunta

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