{"id":13176,"library":"fast-xml-builder","title":"Fast XML Builder","description":"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.","status":"active","version":"1.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/NaturalIntelligence/fast-xml-builder","tags":["javascript","xml","json","fast","builder","parser","js2xml","json2xml","typescript"],"install":[{"cmd":"npm install fast-xml-builder","lang":"bash","label":"npm"},{"cmd":"yarn add fast-xml-builder","lang":"bash","label":"yarn"},{"cmd":"pnpm add fast-xml-builder","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary XML builder class is exported as the default export.","wrong":"import { XMLBuilder } from 'fast-xml-builder';","symbol":"XMLBuilder","correct":"import XMLBuilder from 'fast-xml-builder';"},{"note":"When using CommonJS, explicitly access the `.default` property due to the library's ESM default export.","wrong":"const XMLBuilder = require('fast-xml-builder');","symbol":"XMLBuilder (CommonJS)","correct":"const XMLBuilder = require('fast-xml-builder').default;"},{"note":"Type definition for the configuration options accepted by the XMLBuilder constructor or build method, e.g., 'format', 'indentBy'.","symbol":"XMLExportOptions (Type)","correct":"import type { XMLExportOptions } from 'fast-xml-builder';"}],"quickstart":{"code":"import XMLBuilder from 'fast-xml-builder';\n\nconst builder = new XMLBuilder();\n\n// Example 1: Simple object to XML\nlet xml = builder.build({ name: 'value' });\nconsole.log('Simple XML:', xml); // Output: <name>value</name>\n\n// Example 2: With attributes and nested elements\nconst dataWithAttrs = {\n  root: {\n    '@_id': '123',\n    item: [\n      { '#text': 'First item', '@_type': 'A' },\n      { '#text': 'Second item', '@_type': 'B' }\n    ]\n  }\n};\nconst options = {\n  format: true, // Pretty print the XML\n  indentBy: '  ' // Use two spaces for indentation\n};\nxml = builder.build(dataWithAttrs, options);\nconsole.log('\\nFormatted XML:', xml);","lang":"typescript","description":"Demonstrates basic usage for converting JSON objects to XML, including simple elements, attributes, nested structures, and formatting options."},"warnings":[{"fix":"Install `fast-xml-builder` separately: `npm install fast-xml-builder`. Update your import statements to target this new package.","message":"The 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"While `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pass an options object to the `XMLBuilder` constructor or `build` method: `{ format: true, indentBy: '  ' }` (or your preferred indentation string).","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}