Convert XML to JSON

Convert XML (Extensible Markup Language) to JSON (JavaScript object notation). Control how attributes and values are parsed, remove or include namespaces, and configure more options to format the converted ouput data.

Options

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
import { XMLParser } from "https://cdn.jsdelivr.net/npm/fast-xml-parser@5.3.1/+esm"

export const take = () => [
  { label: "XML", type: "code" },
  { label: "Options", type: "group", value: options },
]

export const make = ([xml, options]) => {
  const parser = new XMLParser(options)
  return [{ type: "json", value: parser.parse(xml) }]
}

const options = [
  {
    key: "ignoreAttributes",
    label: "Ignore attributes",
    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: "allowBooleanAttributes",
    label: "Allow boolean attributes",
    type: "toggle",
  },
  {
    key: "alwaysCreateTextNode",
    label: "Always create text nodes",
    type: "toggle",
  },
  {
    key: "textNodeName",
    label: "Text node name",
    type: "text",
    value: "_text",
    inline: true,
  },
  {
    key: "ignoreDeclaration",
    label: "Ignore XML declaration",
    type: "toggle",
    value: true,
  },
  {
    key: "parseAttributeValue",
    label: "Parse attribute values",
    type: "toggle",
    value: true,
  },
  {
    key: "parseTagValue",
    label: "Parse tag values",
    type: "toggle",
    value: true,
  },
  {
    key: "removeNSPrefix",
    label: "Remove namespace prefixes",
    type: "toggle",
    value: true,
  },
  { key: "trimValues", label: "Trim values", type: "toggle", value: true },
]