# fast-xml-builder

> Build XML from JSON without C/C++ based libraries

Latest version **1.3.1** (published 2026-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-xml-builder
pnpm add fast-xml-builder
yarn add fast-xml-builder
bun add fast-xml-builder
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2026-08-14 |
| First published | 2026-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 218.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 22 |
| Author | Amit Gupta |
| Maintainers | amitgupta |
| Keywords | xml, json, fast, builder, parser, js2xml, json2xml |

## Links

- npm: https://www.npmjs.com/package/fast-xml-builder
- Repository: https://github.com/NaturalIntelligence/fast-xml-builder
- Homepage: https://github.com/NaturalIntelligence/fast-xml-builder#readme
- Issues: https://github.com/NaturalIntelligence/fast-xml-builder/issues
- Funding: https://github.com/sponsors/NaturalIntelligence
- npm.io page: https://npm.io/package/fast-xml-builder

## Dependencies (2)

- [xml-naming](https://npm.io/package/xml-naming.md) ^0.3.0
- [path-expression-matcher](https://npm.io/package/path-expression-matcher.md) ^1.6.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.3.1 (latest) — 2026-08-14
- 1.3.0 — 2026-07-11
- 1.2.1 — 2026-07-03
- 1.2.0 — 2026-05-08
- 1.1.9 — 2026-05-06
- 1.1.8 — 2026-05-05
- 1.1.7 — 2026-05-04
- 1.1.6 — 2026-05-04
- 1.1.5 — 2026-04-17
- 1.1.4 — 2026-03-16
- 1.1.3 — 2026-03-13
- 1.1.2 — 2026-03-11
- 1.1.1 — 2026-03-11
- 1.1.0 — 2026-03-10
- 1.0.0 — 2026-02-25

## README

# fast-xml-builder
Build XML from JSON

[![fast-xml-builder downloads](https://img.shields.io/npm/dw/fast-xml-builder.svg)](https://npm-compare.com/fast-xml-builder) 
[![fast-xml-builder version](https://img.shields.io/npm/v/fast-xml-builder.svg)](https://www.npmjs.com/package/fast-xml-builder)
[![fast-xml-builder license](https://img.shields.io/npm/l/fast-xml-builder.svg)](https://github.com/NaturalIntelligence/fast-xml-builder)

XML Builder was part of [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) for years. But considering that any bug in the parser may false-alarm users who are only using the builder, we have decided to split it into a separate package.

## Installation

```bash
npm install fast-xml-builder
```

## Usage

```javascript
import XMLBuilder from 'fast-xml-builder';

const builder = new XMLBuilder();
const xml = builder.build({ name: 'value' });
```

fast-xml-builder fully supports the response generated by fast-xml-parser. You can use options like `preserveOrder`, `ignoreAttributes`, `attributeNamePrefix`, `textNodeName`, `cdataPropName`, `commentPropName`, `format`, `indentBy`, `suppressEmptyNode`, `suppressUnpairedNode`, `stopNodes`, `oneListGroup`, `maxNestedTags`, and many more.

## Default Options

```js
{
  attributeNamePrefix: '@_',
  attributesGroupName: false,
  textNodeName: '#text',
  ignoreAttributes: true,
  cdataPropName: false,
  commentPropName: false,
  format: false,
  indentBy: '  ',
  suppressEmptyNode: false,
  suppressUnpairedNode: true,
  suppressBooleanAttributes: true,
  preserveOrder: false,
  processEntities: true,
  unpairedTags: [],
  stopNodes: [],
  oneListGroup: false,
  maxNestedTags: 100,
  jPath: true,
  tagValueProcessor: (key, val) => val,
  attributeValueProcessor: (attrName, val) => val,
}
```

## Options Reference

Check [Options reference](docs/Builder_v1.md) for more detail and examples.

- **arrayNodeName**: When building XML from an array, set `arrayNodeName` to wrap each element in a tag name.
- **attributeNamePrefix**: Prefix used to identify attribute properties in the JS object. Default: `'@_'`.
- **attributesGroupName**: Group name for attributes in the JS object. When set, all attributes are expected to be nested under this key. Not supported with `preserveOrder: true`.
- **attributeValueProcessor**: Customize how attribute values are serialized. Receives the attribute name and value.
- **cdataPropName**: Property name that identifies CDATA content. Values under this key are wrapped in `<![CDATA[...]]>`.
- **commentPropName**: Property name that identifies comment content. Values under this key are rendered as `<!-- ... -->`.
- **format**: By default, output is a single-line XML string. Set `format: true` for human-readable, indented output.
- **ignoreAttributes**: By default (`true`), attributes are skipped. Set to `false` to include them. Also supports selective ignoring via an array of strings, array of regular expressions, or a callback function.
- **indentBy**: String used for each level of indentation. Default: `'  '` (two spaces). Only applies when `format: true`.
- **maxNestedTags**: Limits the maximum depth of nested tags. An error is thrown if this depth is exceeded. Default: `100`.
- **oneListGroup**: Groups all repeated child tags under a single parent tag.
- **preserveOrder**: When a JS object was produced by XMLParser with `preserveOrder: true`, pass the same option to XMLBuilder to reconstruct the original XML correctly.
- **processEntities**: When `true` (default), special characters in text and attribute values are replaced with XML entities (`&amp;`, `&lt;`, etc.). Set to `false` for a performance boost when you know your content has no entities. Note: quotes in attribute values are always escaped regardless of this setting.
- **stopNodes**: Tags listed here are treated as raw content containers — their text content is written as-is without entity encoding. Accepts an array of tag name strings or `Expression` instances from `path-expression-matcher`. The old `*.tagName` wildcard syntax is still accepted and automatically converted to the equivalent `..tagName` deep-wildcard syntax.
- **suppressBooleanAttributes**: When `true` (default), attributes with the value `true` are rendered without the value (e.g. `<tag attr>` instead of `<tag attr="true">`).
- **suppressEmptyNode**: When `true`, tags with no text value are rendered as self-closing (`<tag/>`).
- **suppressUnpairedNode**: When `true` (default), unpaired tags are rendered without a closing slash (`<br>`). When `false`, they are rendered as `<br/>`.
- **tagValueProcessor**: Customize how tag text values are serialized. Receives the tag name and value.
- **textNodeName**: Property name representing the text content of a tag in the JS object. Default: `'#text'`.
- **unpairedTags**: List of tag names that have no matching closing tag (e.g. `<br>` in HTML).

---
_Source: https://npm.io/package/fast-xml-builder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
