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

177
Views
Parse XML to JSON or JavaScript object

I am receiving xml data from an api, check this link https://developers.cj.com/docs/rest-apis/advertiser-lookup

I need to parse xml to json or js object in order to use it properly.

I've tried xml2js, it converts stuff in the following way.

<?xml version="1.0" encoding="UTF-8"?>
<cj-api><error-message>  You must provide an Authorization header.</error-message></cj-api>
{
  'cj-api': { 'error-message': [ 'You must provide an Authorization header.' ] }
}

In this case I dont need the array, just the simple value. Is there a working parser that I can use?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can use camaro like this

const { transform } = require('camaro')

async function main() {
    const xml = `
<?xml version="1.0" encoding="UTF-8"?>
<cj-api><error-message>  You must provide an Authorization header.</error-message></cj-api>

`

    const template = {
        errorMessage: '/cj-api/error-message'
    }
    const output = await transform(xml, template)
    console.log(output.message);
}

main()

output

  You must provide an Authorization header.
about 4 years ago · Juan Pablo Isaza 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!