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.