Converts XML to JSON and vice-versa using node-expat parser
Overall
score
93%
Convert an inbound shipment manifest expressed as XML into a clean JSON object that relies on whitespace trimming and non-reversible text node collapsing.
<report><status> ok </status><message>\n Ready for dispatch </message></report>, return { status: "ok", message: "Ready for dispatch" } when requested as an object, trimming surrounding whitespace and avoiding text-node wrappers. @test<report><package id="A1"> Fragile </package><package id="B2">\nHeavy\n</package></report>, return { packages: [{ id: "A1", note: "Fragile" }, { id: "B2", note: "Heavy" }] } with text values as plain strings (no $t or similar). @test<report>\n <status> ok </status>\n <package id="X"> Packed </package>\n</report>), ignore those whitespace-only nodes and emit trimmed text only for elements carrying content. @test@generates
export interface PackageEntry {
id: string;
note: string;
}
export interface CleanReport {
status: string;
message?: string;
packages: PackageEntry[];
}
/**
* Parse manifest XML into a clean object with trimmed text values and collapsed text nodes.
*/
export function parseReport(xml: string): CleanReport;Provides XML to JSON conversion with whitespace trimming and non-reversible text node collapsing.
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