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

275
Vistas
Convert JSON to XML with attributes in Javascript

I need to convert the JSON to XML with some properties as attributes.

For example:

JSON

{
      "Student":{
           "@Studentname":"Ravi",
           "@age":21,
           "college":"Anna University"
       }
}

Desired Output XML

<Student name="Ravi" age=21>
  <college>Anna University</college>
</Student>
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Try the x2js library.

The default attribute prefix is "_" but can be overridden by using the attributePrefix config setting.

const X2JS = window.X2JS;  // node: require('x2js')


const x2js = new X2JS({ attributePrefix:"@" })

const jsonObj = {"Student":{"@Studentname":"Ravi","@age":21,"college":"Anna University"}}

const xmlString = x2js.js2xml(jsonObj)

console.log(xmlString)
<script src="https://unpkg.com/x2js@3.2.3/x2js.js"></script>

about 4 years ago · Santiago Gelvez 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