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

118
Views
La función Json a xml elimina la propiedad vacía

Encontré esta función que convierte JSON a XML, y el JSON que tengo tiene matrices vacías como "filters":[], .

entonces cuando llamo a la función json2xml(json, '') elimina esa matriz vacía, quiero que sea así < filters /> .

Esta función es demasiado compleja para mí, no sé cómo modificarla:

 export default function json2xml(o, tab) { var toXml = function(v, name, ind) { var xml = ""; if (v instanceof Array) { for (var i=0, n=v.length; i<n; i++) xml += ind + toXml(v[i], name, ind+"\t") + "\n"; } else if (typeof(v) === "object") { var hasChild = false; xml += ind + "<" + name; for (var m in v) { if (m.charAt(0) === "@") xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\""; else hasChild = true; } xml += hasChild ? ">" : "/>"; if (hasChild) { for (m in v) { if (m === "#text") xml += v[m]; else if (m === "#cdata") xml += "<![CDATA[" + v[m] + "]]>"; else if (m.charAt(0) !== "@") xml += toXml(v[m], m, ind+"\t"); } xml += (xml.charAt(xml.length-1)==="\n"?ind:"") + "</" + name + ">"; } } else { xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">"; } return xml; }, xml=""; for (var m in o) xml += toXml(o[m], m, ""); return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, ""); }
about 4 years ago · Juan Pablo Isaza
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!