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

274
Views
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 answers
Answer question

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