Convert JSON (JavaScript object notation) to XML (Extensible Markup Language). Control how attributes and values are parsed, remove or include namespaces, and configure more options to format the converted ouput data.
import { XMLBuilder } from "https://cdn.jsdelivr.net/npm/fast-xml-parser@5.3.1/+esm"
export const take = () => [
{ label: "JSON", type: "json" },
{ label: "Options", type: "group", value: options },
]
export const make = ([json, options]) => {
const builder = new XMLBuilder(options)
return [{ type: "code", value: builder.build(json) }]
}
const options = [
{ key: "format", label: "Format output", type: "toggle", value: true },
{
key: "attributeNamePrefix",
label: "Attribute name prefix",
type: "text",
inline: true,
},
{
key: "attributesGroupName",
label: "Attribute group name",
type: "text",
value: "attributes",
inline: true,
},
{
key: "suppressBooleanAttributes",
label: "Suppress boolean attributes",
type: "toggle",
},
{ key: "suppressEmptyNode", label: "Suppress empty nodes", type: "toggle" },
{
key: "arrayNodeName",
label: "Root array node name",
type: "text",
inline: true,
},
{
key: "textNodeName",
label: "Text node name",
type: "text",
value: "_text",
inline: true,
},
]