Converts XML to JSON and vice-versa using node-expat parser
Overall
score
93%
Build a converter that turns a message payload into XML safe for transport, then parses that XML back into the payload without double-encoding reserved characters.
The payload uses a <message> root element. The id, channel, and topic fields are stored as attributes on the root element. The body value is the element's text content.
<core> & "ops" returns XML where those characters are escaped exactly one time in the text content. @testrisk & support (tier 2) appear as single-escaped attribute values (no &amp;). @test<message id="42" channel="alerts" topic="risk & issues">Check <core> & sanitize</message> returns a body of Check <core> & sanitize and topic of risk & issues. @test<, >, &, quotes, or parentheses. @test@generates
export interface MessagePayload {
id: string;
meta: {
channel: string;
topic: string;
};
body: string;
}
/**
* Serializes a payload to XML with attributes for meta fields and text content for the body.
*/
export function toSanitizedXml(input: MessagePayload): string;
/**
* Parses sanitized XML produced by toSanitizedXml back into its raw payload values.
*/
export function fromSanitizedXml(xml: string): MessagePayload;Conversion between XML and JSON with sanitization controls.
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