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

185
Views
xml2js parser ignores the empty string in an array resulting in array size change

xml below to be parsed:

<ENVELOPE>
<ABC>
    <DEF>apple</DEF>
    <GHI>4</GHI>
    <JKL>85</JKL>
</ABC>
<MNO>add</MNO>
<PQR></PQR>
<STU></STU>
</ENVELOPE>

and response after parsing:

{

"ENVELOPE": { "ABC": { "DEF": "apple", "GHI": "4", "JKL": "85" }, "MNO": "add" } }

The other two tags has been discarded by the xml2js parses. But i need it there to be empty atleast. Have tried using options of the parser but no luck yet

Here is my code to get the parser:

private getParser() {
let nameToLowerCase = (name: string): string => {
  return name.toLowerCase();
}

let options: xml2js.Options = {
  attrkey: '_',
  charkey: '$',
  explicitCharkey: true,
  emptyTag: null,
  normalize: true,
  normalizeTags: true,
  explicitArray: false,
  trim: true,
  tagNameProcessors: [nameToLowerCase],
  attrNameProcessors: [nameToLowerCase]
};

return new xml2js.Parser(options);

}

over 4 years ago · Santiago Trujillo
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!