Converts XML to JSON and vice-versa using node-expat parser
Overall
score
93%
Produce reversible JSON from XML while letting callers choose the property name used for text content. The converter must keep attributes intact and make text values accessible under the caller's preferred key so downstream code can rely on consistent shapes.
<message from="bot">Hello!</message> with textKey: "content" yields an object where the element text lives under content and attributes stay alongside it. @testtextKey: true converts <note>Hi</note> into an object that stores the text under _t, enabling a compact reversible shape. @test<item>42</item> produces an object that uses the conventional $t text property while preserving element structure. @test@generates
/**
* Convert XML content into a reversible JSON-friendly object while controlling the text property name.
*
* @param {string|Buffer} xmlInput - XML input to convert.
* @param {{ textKey?: string|boolean }} [options] - Text key selection; string uses that key, true uses "_t", omit for default.
* @returns {object} Parsed object representation with the requested text key.
*/
export function convertXmlWithTextKey(xmlInput, options);Provides XML-to-JSON conversion with configurable text node keys.
Install with Tessl CLI
npx tessl i tessl/npm-xml2jsondocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10