fast-xml-parser: Build xml with attributes and child elements from json

I'm using fast-xml-parser to create xml documents from json. In the examples they show how to create an element with attributes

const jsOrderedObj = [
        "?textinfo": [
                "#text": ""
        ":@": {
            "@_whitespace": true,
            "@_is": true,
            "@_allowed": true
const options = {
    ignoreAttributes: false,
    preserveOrder: true,
    allowBooleanAttributes: true,
    suppressBooleanAttributes: true
const builder = new XMLBuilder(options);
const output =;


<?textinfo   whitespace is allowed?>

And examples of how to create an XML document with child elements:

const xmlData = {
            'foo': {
                'bar': 'data',
                'bar2': 'data2',
                'bar3': 'data3',
                'bar4': 'data4',
const builder = new XMLBuilder({});
const output =;



Now my question is, how should I define my json, to get both attributes and child elements in my xml, like this:

<foo whitespace is allowed><bar>data</bar><bar2>data2</bar2><bar3>data3</bar3><bar4>data4</bar4></foo>
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum