The integration was supposed to be simple: your side has the data as JSON, and the older system on the other side wants XML. Then the first test file comes back rejected, because the receiving system does not want XML in general. It wants its XML: a particular root element, attributes in particular places, repeated elements in a particular order.

That gap between "valid XML" and "the XML this system accepts" is where these conversions succeed or fail. This guide walks through it with the free JSON to XML Converter on Ovatly: how its mapping works, how to shape your JSON so the output lands in the right form, and how to prove the result with a single record before you convert thousands.

Contents

  • Quick answer
  • The mapping the converter applies
  • Shape the JSON before you convert
  • How to convert, step by step
  • Worked example: one person record
  • Test with one record before the full set
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

Shape the JSON for the mapping first: keys become elements, keys starting with @ become attributes, and #text becomes text content. Then open the JSON to XML Converter, paste the JSON, set the root element name the receiving system expects, and convert. Download converted.xml. Before converting the full set, convert one record and compare it against a sample the legacy system already accepts, because the converter produces one consistent dialect of XML and does not know your system's schema. If the shapes differ, adjust the JSON and convert again.

The mapping the converter applies

The conversion is deterministic: the same JSON always produces the same XML, following fixed rules.

  • A key becomes an element with that name.
  • A key starting with @ becomes an attribute on its parent element instead of a child element.
  • A #text key becomes the text content of its parent element.
  • An array repeats its element: each item gets its own element with the same name, in order.
  • A null value becomes an empty element, present but with no content.
  • Special characters in values are escaped, so text containing characters such as & or < cannot break the document.
  • Keys that are not valid XML names are repaired: invalid characters are replaced with underscores, and a key starting with a digit gets an underscore prefix.

You also choose the root element name, which matters more than it sounds: many legacy systems identify a document by its root before they read anything inside it.

Shape the JSON before you convert

Because the mapping is fixed, the lever you control is the input. Decide, for each piece of data, whether the receiving system expects it as an attribute or as a child element, and write the JSON to match. Identifiers and codes are often attributes in older XML designs, while descriptive content is usually elements, and mixed content belongs in #text.

For example, a record shaped like this:

{"person":{"@id":"7","name":"Ana","tag":["a","b"]}}

already declares its intent: id is an attribute, name is an element, and tag is a repeated element. If your JSON currently keeps id as a plain key, it will arrive as a child element, which may be exactly what the receiving system rejects. Reshaping the JSON is quick; debugging a rejected batch of ten thousand records is not.

How to convert, step by step

  1. Open the JSON to XML Converter and paste a single record of your JSON, shaped for the mapping as described above.
  2. Set the root element name to the one the receiving system expects.
  3. Convert and download converted.xml.
  4. Compare the output against a sample document the system already accepts: root name, attribute placement, element order, repeated elements.
  5. When the single record matches, convert the full set with the same JSON shape and root name.

Worked example: one person record

Take the shaped record from above:

{"person":{"@id":"7","name":"Ana","tag":["a","b"]}}

The converter produces:

<person id="7">
  <name>Ana</name>
  <tag>a</tag>
  <tag>b</tag>
</person>

Read it against the mapping: person is the root element, @id became the attribute id="7", name became a child element holding Ana, and the two item array became two tag elements in order. Nothing was renamed, reordered or dropped. That predictability is the point: if this output is not the shape your system wants, the fix is in the JSON, not in hoping the converter guesses differently.

Test with one record before the full set

A legacy system with a strict schema will reject a document over one misplaced attribute, and it will reject ten thousand records just as fast as one. So the cheap test is always the same: convert one record, place it next to a known good sample from the receiving system, and compare element by element.

Check the root name first, then attribute placement, then whether repeated values repeat as sibling elements, then how empty values appear. If the converter's dialect differs from the schema in a way reshaping cannot fix, it is far better to learn that from one record than from a failed import. The converter runs fully locally in your browser, so test conversions cost nothing and expose no data.

Limitations and honest tradeoffs

The converter emits one consistent dialect of XML, produced by the fixed mapping above. It does not know your system's schema, it does not validate the output against that schema, and a schema strict system may still need the result adjusted after conversion. Reshaping the JSON covers attribute placement, text content and repetition, but it cannot express every construct an arbitrary schema might demand.

It also converts in one direction, from JSON to XML, and it repairs invalid key names with underscores rather than asking you, so check the output names against your sample if your keys contain spaces, digits at the start or other characters XML forbids.

Common mistakes

  • Converting the full set first. A shape error repeated ten thousand times is still one shape error. Test with one record.
  • Leaving identifiers as plain keys. They arrive as child elements. If the system expects attributes, prefix the keys with @ in the JSON.
  • Assuming valid XML means accepted XML. The output can be perfectly valid and still the wrong dialect for a strict schema. Compare against a known good sample.
  • Ignoring the root element name. Systems often route or reject documents on the root alone. Set it deliberately.
  • Forgetting that key repairs change names. Underscore replacements keep the XML valid, but the receiving system sees the repaired name, not your original key.

FAQs

Does the converter know my legacy system's schema? No. It applies one consistent mapping and produces one dialect of XML. A system built for a specific schema may need the result adjusted, which is why you test with one record first.

How do I make an XML attribute instead of an element? Prefix the key with @ in the JSON. A key such as @id becomes an attribute on its parent element, while plain keys become child elements.

What happens to arrays? Each item becomes its own element with the same name. An array of two tags produces two tag elements, in order.

What if a key starts with a number or contains spaces? XML names cannot start with a digit or contain invalid characters. The converter replaces invalid characters with underscores and gives digit-leading keys an underscore prefix, so the output stays valid XML.

What does a null value become? An empty element. The key is present in the XML with no content, which keeps the record's shape intact for the receiving system.

Conclusion

Converting JSON to XML for a legacy system is a shaping exercise, not a button press: write the JSON so the JSON to XML Converter mapping produces the attributes, elements and root your system expects, then prove it with one record before the full set. When the JSON itself needs to get smaller before any of this, our companion guide on reducing JSON size further after minifying covers those tradeoffs, and the Data and JSON Tools guides collect the rest of this series.

References