Converts XML to JSON and vice-versa using node-expat parser
Overall
score
93%
Design a tiny utility that converts XML into a reversible JSON representation and back again while keeping text nodes explicit so that round-trips preserve content.
<message>Hello world</message> with default settings yields { "message": { "$t": "Hello world" } }, showing text content stored under the default text node key instead of collapsing into a string. @test<note priority="high">Reminder</note>, converting to reversible JSON then back to XML returns <note priority="high">Reminder</note> with the text node preserved under the text key in JSON. @testtextKey: "textNode" on <title>Hi</title>, the reversible JSON includes "textNode": "Hi" and round-tripping yields <title>Hi</title>. @test@generates
export function toReversibleJson(xmlInput, options?: { textKey?: string }): object;
export function roundTripXml(xmlInput, options?: { textKey?: string }): string;The textKey option defaults to $t when omitted, and both functions should work with plain JavaScript objects (not serialized JSON strings) for the reversible representation.
Provides reversible XML <-> JSON conversion that retains text nodes for round-tripping.
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