Build XML from JSON
XML Builder was part of 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.
npm install fast-xml-builder
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.
{
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,
}
Check Options reference for more detail and examples.
arrayNodeName to wrap each element in a tag name.'@_'.preserveOrder: true.<![CDATA[...]]>.<!-- ... -->.format: true for human-readable, indented output.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.' ' (two spaces). Only applies when format: true.100.preserveOrder: true, pass the same option to XMLBuilder to reconstruct the original XML correctly.true (default), special characters in text and attribute values are replaced with XML entities (&, <, 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.Expression instances from path-expression-matcher. The old *.tagName wildcard syntax is still accepted and automatically converted to the equivalent ..tagName deep-wildcard syntax.true (default), attributes with the value true are rendered without the value (e.g. <tag attr> instead of <tag attr="true">).true, tags with no text value are rendered as self-closing (<tag/>).true (default), unpaired tags are rendered without a closing slash (<br>). When false, they are rendered as <br/>.'#text'.<br> in HTML).Build XML from JSON
XML Builder was part of 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.
npm install fast-xml-builder
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.
{
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,
}
Check Options reference for more detail and examples.
arrayNodeName to wrap each element in a tag name.'@_'.preserveOrder: true.<![CDATA[...]]>.<!-- ... -->.format: true for human-readable, indented output.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.' ' (two spaces). Only applies when format: true.100.preserveOrder: true, pass the same option to XMLBuilder to reconstruct the original XML correctly.true (default), special characters in text and attribute values are replaced with XML entities (&, <, 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.Expression instances from path-expression-matcher. The old *.tagName wildcard syntax is still accepted and automatically converted to the equivalent ..tagName deep-wildcard syntax.true (default), attributes with the value true are rendered without the value (e.g. <tag attr> instead of <tag attr="true">).true, tags with no text value are rendered as self-closing (<tag/>).true (default), unpaired tags are rendered without a closing slash (<br>). When false, they are rendered as <br/>.'#text'.<br> in HTML).11 followers · starred Jul 2026