About the XML to JSON Converter
XML and JSON do not map one to one, so every converter has to make choices, and the useful thing is to make them visible. Here, each element becomes an object key; attributes become keys with a prefix (default @) so they cannot collide with child elements; text inside an element that also has children or attributes is stored under #text; and an element that repeats under the same parent becomes an array. An element with only text becomes a plain value.
With type conversion on, text that looks like a number, true, false or null becomes the JSON type; turn it off when identifiers such as postcodes or version strings must stay text. Empty elements become null. The root element wraps the whole result unless you tick the option to drop it.
Namespace prefixes are kept in key names (soap:Body), which is usually what you want for SOAP responses. For the reverse direction use JSON to XML; a document converted there and back keeps its structure, though attributes will have become child elements.
How to use
- Paste XML on the left.
- Set the attribute prefix, decide whether values should be typed, and whether to keep the root element.
- Copy the JSON. Swap opens it in JSON to XML to check the round trip.
Common questions
- Why is a single child an object but two children an array?
- An element that appears once has no way to signal that it is a list. If you need arrays always, post-process the output, or wrap single items in a known list element before converting.
- What happens to XML comments?
- They are dropped. JSON has no comments.
- How are CDATA sections handled?
- As text: the content of a CDATA block becomes the string value of its element.
- Can I get attributes without a prefix?
- Set the prefix field to empty. Be aware that an attribute and a child element with the same name would then overwrite each other.