XML to JSON converts XML documents to typed JSON and reverses the process for JSON to XML emission. Preserve flags capture attributes as @-prefixed keys, record xmlns prefixes in a namespaces array, and count CDATA sections. Bidirectional with a configurable root element produces faithful round-trip conversion that no commodity tool offers.
XML to JSON
Bidirectional XML ↔ JSON with attribute, namespace, and CDATA preservation
How to use
- Pick mode — Choose "XML → JSON" to convert XML to JSON, or "JSON → XML" to emit XML from JSON.
- Toggle preserve flags — Enable Preserve Attributes (@-prefix keys), Preserve Namespaces (stats.namespaces[]), or Preserve CDATA (counted in stats). All three default ON for fidelity.
- Set root element (JSON → XML only) — Name the root element for the emitted XML. Defaults to "root" when omitted.
- Paste your input — XML or JSON, depending on mode. The textarea accepts up to several thousand characters.
- Run — Click Convert or press Ctrl+Enter. The output, element/attribute/namespace/CDATA stats, and any warnings appear in the output panel.
MCP / API
Call xml_to_json directly from any MCP-compatible agent:
// MCP TypeScript SDK
const result = await client.callTool({
name: "xml_to_json",
arguments: {
"input": "...",
"mode": "xml-to-json",
"preserveAttributes": false,
"preserveNamespaces": false,
"preserveCDATA": false
}
});
// curl
curl -X POST https://obfus.link/mcp \
-H "Authorization: Bearer <SPT>" \
-H "Content-Type: application/json" \
-d '{"method":"tools/call","params":{"name":"xml_to_json","arguments":{"input":"...","mode":"xml-to-json","preserveAttributes":false,"preserveNamespaces":false,"preserveCDATA":false}}}'Related tools
FAQ
How are attributes represented in the JSON output?
Attributes are prefixed with @ in the JSON keys. For example, <item id="42">x</item> becomes { "item": { "@id": "42", "#text": "x" } }. This is the canonical xml2js / fast-xml-parser convention and round-trips back to valid XML in json-to-xml mode.
What is the difference between the stats fields when preserve flags are off?
The output JSON or XML still drops the metadata, but the stats counts reflect the toggle state. preserveAttributes:false → stats.attributes is 0. preserveNamespaces:false → stats.namespaces is []. preserveCDATA:false → stats.cdataSections is 0. The underlying parse still happens — only the reporting and emission are suppressed.
Can it handle SOAP envelopes?
Yes. SOAP envelopes use namespaces extensively, so enable preserveNamespaces to see which prefixes appear in stats.namespaces[]. The body of the envelope is parsed as nested elements and converted to JSON in the standard way.
What happens with mixed content (text and elements interleaved)?
Mixed content is detected and emitted as a warning in the warnings array. The text portion is concatenated into the #text key alongside the element children. This works correctly for most cases, but order between text and element siblings is not preserved.
Can I use this tool via the MCP API?
Yes. The tool is registered on the obfus.link MCP server at https://obfus.link/mcp. Call it from any MCP-compatible agent with a Shared Payment Token. The MCP tool name matches the snake_case slug shown in the integration snippet.