Boneyard Tools

How JSON structures map onto XML

The rules this converter follows when it turns objects, arrays, primitives and awkward keys into valid, readable XML markup.

Two data models that do not line up

JSON and XML both describe structured data, yet they rest on different ideas. JSON has objects, arrays, strings, numbers, booleans and null as first-class types, while XML knows only elements, attributes and text. Converting between them means making deliberate choices about how a typed, ordered JSON tree becomes a tree of named tags. This converter favours simple, predictable output over a clever round-trip, so the XML it produces is easy to read and easy to feed into other tools.

Objects and arrays

Each key in a JSON object becomes a child element named after that key, and nested objects nest their elements the same way. Arrays are the interesting case, because XML has no array type. The converter emits one element per array item and reuses the parent key as the tag name, so a list of three values under prices produces three <prices> siblings. When the very top of the document is an array, there is no key to borrow, so each item is wrapped in a neutral <item> element instead.

Primitives, nulls and escaping

Strings, numbers and booleans all become plain text inside their element, with numbers and booleans stringified as they appear. A null value produces an empty element that preserves the shape of the data without asserting a value. Any text that contains the reserved characters ampersand, less-than, greater-than or double quote is escaped to the matching XML entity, which keeps the output well-formed even when your data holds HTML snippets or math symbols.

Making keys into legal element names

XML is strict about element names, which rules out spaces and many punctuation marks and forbids a name that starts with a digit, a dot or a hyphen. The converter sanitises each key by replacing disallowed characters with underscores and, when needed, prefixing a leading underscore. That means a key like first name becomes first_name and a key like 2024 becomes _2024, so the document parses cleanly in any XML reader even if the original JSON used loose key names.

Frequently asked questions

Why does my array not have a wrapper element?

By design. The converter repeats the key for each item rather than nesting them under a single container, so three tags share the same name. If you need a wrapper, add one key level in your JSON before converting.

Will the XML declaration always appear?

The tool emits the <?xml version="1.0" encoding="UTF-8"?> line at the top of the output. It sits above the root element and states the version and encoding for parsers that expect it.