CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-xml2json

Converts XML to JSON and vice-versa using node-expat parser

Overall
score

93%

Overview
Eval results
Files

task.mdevals/scenario-5/

Sanitized Message Bridge

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.

Capabilities

Escape reserved characters once

  • Converting a payload whose body contains <core> & "ops" returns XML where those characters are escaped exactly one time in the text content. @test
  • Meta values containing symbols such as risk & support (tier 2) appear as single-escaped attribute values (no &amp;amp;). @test

Parse sanitized XML to raw payload

  • Parsing a sanitized XML string like <message id="42" channel="alerts" topic="risk &amp; issues">Check &lt;core&gt; &amp; sanitize</message> returns a body of Check <core> & sanitize and topic of risk & issues. @test
  • Running the XML export then parse functions in sequence restores the original payload strings, even when the input contains <, >, &, quotes, or parentheses. @test

Implementation

@generates

API

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;

Dependencies { .dependencies }

xml2json { .dependency }

Conversion between XML and JSON with sanitization controls.

Install with Tessl CLI

npx tessl i tessl/npm-xml2json

tile.json