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

Reversible XML Text Preservation

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.

Capabilities

Generates reversible JSON with explicit text nodes

  • Converting <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

Round-trips XML with attributes intact

  • Given <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. @test

Supports custom text node keys

  • When called with textKey: "textNode" on <title>Hi</title>, the reversible JSON includes "textNode": "Hi" and round-tripping yields <title>Hi</title>. @test

Implementation

@generates

API

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.

Dependencies { .dependencies }

xml2json { .dependency }

Provides reversible XML <-> JSON conversion that retains text nodes for round-tripping.

Install with Tessl CLI

npx tessl i tessl/npm-xml2json

tile.json