1001Ferramentas
🔄Converters

JSON ↔ XML Converter

Convert between JSON and XML preserving attributes via @attr and text via #text, with pretty-print of the resulting XML.

Use chaves prefixadas com @ para atributos XML e #text para texto interno.


    

When the system on the other end only speaks XML

Your API returns JSON, the client's system demands XML, and somebody in between has to translate. It comes up constantly with legacy ERPs, SOAP services and government filing formats. Instead of writing a throwaway script just to check that the structure comes out right, you paste on one side and read the result on the other, in either direction, with a sample button so you can see the convention before risking your real payload.

The translation follows a convention worth understanding before you trust the output: keys starting with an at-sign become element attributes, and the special text key becomes the node's content. So an object with an at-id key and a name field turns into a tag carrying id as an attribute and name as a child. Going the other way, sibling elements sharing a name collapse into an array. That is where the classic trap lives: an element appearing once comes back as an object, and the very same element appearing twice comes back as a list.

Because of that, whatever consumes JSON produced from XML has to normalise before iterating, or the code breaks precisely on the single-item case. Test with a minimal example and again with a repeated element before signing off on the integration contract. The whole conversion runs in the browser with no network calls, so you can paste a staging payload without wondering where it ends up.

Frequently asked questions

How do XML attributes show up in the JSON?
As keys prefixed with an at-sign. A tag's id attribute becomes the at-id key on the matching object, and loose element text becomes the hash-text key.
Why do I sometimes get an object and sometimes an array?
The rule mirrors XML: an element appearing once becomes an object, while two or more siblings with the same name become an array. Normalise in your code before looping.
Is the pasted content sent to a server?
No. The conversion happens in your own browser in JavaScript, with no network request. Close the tab and nothing is left behind.

Related Tools