Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
Adding quotation makes to JSON String which contains some XML values

I'm trying to format a JSON input string in Javascript so that I can use it as a map.

{accountNumber:E22E6178D16777E1E053020011AC64B0,paymentMethodObject:<ns2:Token>123</ns2:Token><ns2:Type>CreditCard</ns2:Type>,preview:true}

To do this I need to put quotation marks around each key and value. Like here:

{
    "accountNumber": "12345",
    "paymentMethodObject": "<ns2:Token>123</ns2:Token><ns2:Type>CreditCard</ns2:Type>",
    "preview": "true"
}

The problem is when I try to do it, quotes get added to the XML values also because they also contain a colon.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Maybe you need to use method replace with pattern Regex that match key:value replace it with surrounded by quotes pair!

let strJSON = '{accountNumber:E22E6178D16777E1E053020011AC64B0,paymentMethodObject:<ns2:Token>123</ns2:Token><ns2:Type>CreditCard</ns2:Type>,preview:true}';
let objJSON = strJSON.replace(/(\w+):([\/<>:\w+]+)/g,'"$1":"$2"');
console.log(objJSON)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda