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-3/

XML Payload Converter

Transforms XML payloads into JavaScript-safe JSON for downstream processing.

Capabilities

Convert XML to JSON string

  • Converts a simple XML document with attributes and text into a JSON string matching the structure, trimming surrounding whitespace, and ensuring JS-safe escaping for special line separators. @test

Escape unsafe characters

  • XML containing U+2028 or U+2029 in text nodes yields a JSON string where those characters are escaped so the string can be inlined in JS code safely. @test

Object output with array selection

  • When configured for object output and given tag names that should always be arrays, repeated elements and forced tags are returned as arrays in the resulting object. @test

Optional sanitization

  • When sanitization is enabled, angle brackets, ampersands, and quotes inside text and attribute values are preserved in the JSON output without breaking structure. @test

Implementation

@generates

API

export type ArrayTags = string[] | boolean;

export interface XmlToJsonOptions {
  asObject?: boolean;
  arrayTags?: ArrayTags;
  sanitize?: boolean;
  textKey?: string;
  coerce?: boolean;
}

export function xmlToJson(
  xmlInput: string | Buffer,
  options?: XmlToJsonOptions
): string | Record<string, unknown>;

Dependencies { .dependencies }

xml2json { .dependency }

Used to convert XML input to JSON while handling JS-safe escaping, optional sanitization, and array coercion. @satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-xml2json

tile.json