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

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

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