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

Null-safe Inventory XML

Generate an XML feed for storefront inventory where null optional fields are removed unless explicitly included.

Capabilities

Omit null children by default

  • When inventory includes optional fields set to null (e.g., description: null), the generated XML excludes those element tags while retaining siblings, including other optional fields with actual values. @test

Preserve empty and falsy non-null values

  • Fields containing empty string "", numeric zero 0, or boolean false still emit elements with those values, demonstrating that only null is suppressed. @test

Allow explicit null emission

  • When caller requests null emission, null-valued fields produce empty elements (e.g., <description/>) so feeds can show explicit placeholders. @test

Implementation

@generates

API

/**
 * Builds an XML string representing an inventory feed with optional suppression of null fields.
 *
 * @param {object} inventory - Root object with an `items` array of records containing identifiers and optional metadata.
 * @param {object} [options]
 * @param {boolean} [options.includeNull=false] - Emit empty elements for null-valued fields when true; otherwise omit them.
 * @returns {string} XML string encoding the inventory data.
 */
export function buildInventoryXml(inventory, options = {});

Dependencies { .dependencies }

xml2json { .dependency }

Converts JS objects to XML while supporting omission of null-valued children. @satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-xml2json

tile.json