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

Custom Text Node JSON Conversion

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.

Capabilities

Custom string text key

  • Converting <message from="bot">Hello!</message> with textKey: "content" yields an object where the element text lives under content and attributes stay alongside it. @test

Short text key toggle

  • Passing textKey: true converts <note>Hi</note> into an object that stores the text under _t, enabling a compact reversible shape. @test

Default reversible key

  • When no text key is provided, converting <item>42</item> produces an object that uses the conventional $t text property while preserving element structure. @test

Implementation

@generates

API

/**
 * 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);

Dependencies { .dependencies }

xml2json { .dependency }

Provides XML-to-JSON conversion with configurable text node keys.

Install with Tessl CLI

npx tessl i tessl/npm-xml2json

tile.json