Registry / serialization / fast-xml-builder

fast-xml-builder

JSON →
library1.1.5jsnpmunverified

fast-xml-builder is a JavaScript/TypeScript library designed to efficiently construct XML documents from JSON objects without relying on C/C++ native addons, ensuring broad compatibility across different environments. It is currently at version 1.1.5 and is actively maintained, having been split from its parent project, `fast-xml-parser`, to provide a more focused and independent XML building solution. This separation allows for distinct development cycles and reduces potential issues for users solely interested in XML generation. The library differentiates itself by offering extensive configuration options, many of which are directly compatible with `fast-xml-parser`'s output structure, such as `preserveOrder`, `ignoreAttributes`, `attributeNamePrefix`, and `format`. This ensures seamless integration for workflows involving both parsing and building XML using the `fast-xml` ecosystem. Its release cadence is tied to its upstream `fast-xml-parser` counterpart, with updates released as needed to maintain compatibility and introduce new features.

npm install fast-xml-builder
INSTALL
IMPORT
SIG · FAST-XML-BUILDER
F
fast-xml-builder
serializationjavascriptv1.1.5
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

XMLBuilder
✓ import XMLBuilder from 'fast-xml-builder';
✗ import { XMLBuilder } from 'fast-xml-builder';
The primary XML builder class is exported as the default export.
XMLBuilder (CommonJS)
✓ const XMLBuilder = require('fast-xml-builder').default;
✗ const XMLBuilder = require('fast-xml-builder');
When using CommonJS, explicitly access the `.default` property due to the library's ESM default export.
XMLExportOptions (Type)
✓ import type { XMLExportOptions } from 'fast-xml-builder';
Type definition for the configuration options accepted by the XMLBuilder constructor or build method, e.g., 'format', 'indentBy'.

Demonstrates basic usage for converting JSON objects to XML, including simple elements, attributes, nested structures, and formatting options.

import XMLBuilder from 'fast-xml-builder'; const builder = new XMLBuilder(); // Example 1: Simple object to XML let xml = builder.build({ name: 'value' }); console.log('Simple XML:', xml); // Output: <name>value</name> // Example 2: With attributes and nested elements const dataWithAttrs = { root: { '@_id': '123', item: [ { '#text': 'First item', '@_type': 'A' }, { '#text': 'Second item', '@_type': 'B' } ] } }; const options = { format: true, // Pretty print the XML indentBy: ' ' // Use two spaces for indentation }; xml = builder.build(dataWithAttrs, options); console.log('\nFormatted XML:', xml);
Debug
Known issues
breakingThe XML builder functionality was extracted from the `fast-xml-parser` package into this standalone `fast-xml-builder` package. Projects previously relying on `fast-xml-parser` for both parsing and building will now need to explicitly install `fast-xml-builder` as a separate dependency.
fix
Install `fast-xml-builder` separately: `npm install fast-xml-builder`. Update your import statements to target this new package.
affects: >=1.0.0
gotchaWhile `fast-xml-builder` maintains high compatibility with `fast-xml-parser`'s data structures and many options, it's crucial to correctly configure builder-specific options such as `format`, `indentBy`, `suppressEmptyNode`, etc. Incorrect or missing options can lead to unexpected XML output formatting or structure.
fix
Always refer to the `fast-xml-builder` documentation or the `XMLExportOptions` type definition for a comprehensive list of available options and their expected behavior to ensure your desired XML output.
affects: >=1.0.0
gotchaThe default behavior of `fast-xml-builder` creates compact XML without formatting. If you require human-readable, formatted XML with indentation, you must explicitly enable the `format: true` option and configure `indentBy` during the builder's instantiation or when calling the `build` method.
fix
Pass an options object to the `XMLBuilder` constructor or `build` method: `{ format: true, indentBy: '  ' }` (or your preferred indentation string).
affects: >=1.0.0
Upgrade
Version history
1.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
fast-xml-builder — npm install fast-xml-builder · libregistry