Skip to content
toolbelt
Back to Guides

Producing XML a Legacy System Will Accept

By ·

Updated

Hand-built XML from a template is how you get "unexpected character" at the worst moment. Generate it properly.

What is this tool?

JSON to XML turns objects into elements. The interesting part is escaping and naming, because XML is stricter about both than JSON is.

How it works

Keys become element names, values become text or attributes, and every string is escaped so an ampersand or angle bracket does not break the document. Keys that are not valid XML names are handled explicitly rather than silently emitting broken markup.

Example

{"user":{"id":"42","name":"O'Brien & Co"}}

becomes
<root>
  <user>
    <id>42</id>
    <name>O'Brien &amp; Co</name>
  </user>
</root>

When to use it

Building a request body for an older enterprise endpoint. Producing an RSS or sitemap-shaped document. Generating config for a tool that only reads XML.

Optimization Tips

Escape first, then send. An unescaped ampersand is the most common reason a hand-built XML payload is rejected, and the error message from the other side rarely says so plainly.

Frequently Asked Questions

Why is my key invalid as a tag?
XML names cannot start with a digit and cannot contain spaces. Rename or use an attribute.
How are arrays handled?
Each item becomes a repeated element with the same name, which is the standard XML idiom.
Can null be represented?
XML has no null. An empty element is the usual convention.
Does it add an XML declaration?
Not by default. Add <?xml version="1.0" encoding="UTF-8"?> yourself if the receiving system wants it.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools