The conversion finished without an error, the file downloaded, and the receiving system rejected it anyway. When JSON to XML goes wrong, it rarely goes wrong at random. The same handful of mapping surprises cause almost every failure: an attribute that arrived as an element, a list that flattened out, a key that changed its name.

The JSON to XML Converter on Ovatly follows a small set of deterministic rules, so its output is completely predictable once you know them. This guide walks through the mistakes those rules produce when your JSON is not shaped for them.

Contents

  • Quick answer
  • The mapping rules that decide everything
  • Mistake 1: expecting a plain key to become an attribute
  • Mistake 2: expecting an array to sit under one wrapper
  • Mistake 3: expecting a nested object to repeat like an array
  • Mistake 4: keys quietly renamed
  • Mistake 5: reading an empty element as missing data
  • How to convert, step by step
  • Worked example: one record, two surprises
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

JSON to XML mistakes come from one source: the mapping is fixed, and your JSON was not shaped for it. Keys become elements, only keys starting with @ become attributes, the #text key becomes text content, arrays repeat their element, and null becomes an empty element. Invalid XML names get renamed with underscores. Before converting, rename attribute fields so they start with @, hold lists in arrays under the element name you want repeated, and accept that the output is one consistent dialect that may still need adjusting.

The mapping rules that decide everything

Every surprise in this guide traces back to six rules. Keys become elements. A key starting with @ becomes an attribute on its parent element. A key named #text becomes the text content of its parent. An array repeats its element once per item. A null value becomes an empty element. You choose the root element name.

Two more behaviours sit behind the rules. Special characters in values are escaped, so text survives intact. And because XML names are stricter than JSON keys, invalid name characters are replaced with underscores and digit-leading keys get an underscore prefix. The values never change; only the shape and the names can move.

Mistake 1: expecting a plain key to become an attribute

JSON has no attributes, so writers often store an identifier as an ordinary key and expect the converter to promote it. It will not. A key named id becomes an <id> element inside its parent, because every plain key is treated as an element. The data lands in the wrong place: the receiving system looks for an attribute on the parent, finds none, and reports the record as incomplete.

The fix happens in your JSON, before conversion: rename the key so it starts with @, and the same value is written as an attribute. Which fields are attributes is a modelling choice made while shaping the input, not a setting you toggle afterwards.

Mistake 2: expecting an array to sit under one wrapper

Many XML formats wrap repeated items in a container: one parent element holding several child elements. The converter does not build that wrapper. An array repeats its own element, so two values under the key tag become two <tag> elements side by side, with nothing around them.

If the system you are feeding expects a wrapper, build it yourself in the JSON: give the wrapper its own key and place the array inside it, and the repeated elements appear inside that parent.

Mistake 3: expecting a nested object to repeat like an array

The reverse surprise catches people too. An array repeats, but a nested object does not: it converts once, as a single element with its own children. If your JSON holds one object where the format expects several repeated elements, the output contains exactly one, and the missing repetitions look like lost data.

Repetition comes only from arrays. When a field can occur more than once, model it as an array even when the current record holds a single item, so the output shape stays stable from record to record.

Mistake 4: keys quietly renamed

JSON keys can contain spaces, punctuation and leading digits. XML element names cannot. When a key breaks the naming rules, the converter renames it rather than failing: invalid characters become underscores, and digit-leading keys get an underscore prefix.

The conversion succeeds and the values are all present, so this mistake hides well. It surfaces later, when a downstream system searches for the original name and finds nothing. After converting, compare output element names against your input key names, especially keys with spaces, hyphens or numeric starts.

Mistake 5: reading an empty element as missing data

A null in JSON is explicit: the field exists and its value is nothing. In the XML output, that field becomes an empty element, with nothing between its tags. The conversion lost nothing, but readers on the other side often interpret an empty element as a field that was never sent.

If the distinction matters, decide how nulls are represented before you convert, and check the empty elements afterwards.

How to convert, step by step

  1. Shape your JSON first: rename attribute fields so their keys start with @, put repeated fields in arrays, and use #text for text inside an element with attributes.
  2. Open the JSON to XML Converter, paste your JSON, and choose the root name the format expects.
  3. Convert and download the result as converted.xml.
  4. Check the output: attributes in place, elements repeated, no renamed keys, nulls accounted for.

Worked example: one record, two surprises

Take this record:

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

Converted with person as the root, it produces:

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

Two rules are visible here. The @id key became the attribute id="7" on the <person> element, while the plain key name became a child element, and the tag array repeated its element twice with no wrapper around the pair. Write the same record with a plain id key instead of @id and the identifier drops into a child <id> element: mistake 1 in action.

Limitations and honest tradeoffs

The converter produces one consistent dialect. It applies the same rules to every input, so the output is predictable, but it does not reshape that output for a particular schema. If the system you are feeding follows a strict schema, treat the converted file as a correct starting point and adjust it where the schema demands a different shape.

The renaming behaviour is a tradeoff of the same kind: it keeps the conversion moving and preserves the data, but it changes names silently, so checking afterwards is part of the job.

Common mistakes

  • Storing identifiers as plain keys. Without the @ prefix they become elements, not attributes.
  • Expecting a wrapper around repeated items. Arrays repeat their element; build the wrapper as a parent key.
  • Modelling a repeatable field as a single object. Only arrays repeat, so output shape changes per record.
  • Skipping the name check. Keys with invalid characters or a leading digit are renamed with underscores.
  • Treating empty elements as lost data. A null converts to an empty element; it was empty in the source too.

FAQs

Why did my id field become an element instead of an attribute? Because the key did not start with @. A plain key such as id always becomes a child element. Rename it to @id in your JSON and it will be written as an attribute on its parent element.

Why is there no wrapper element around my list items? Arrays repeat their element once per item instead of nesting under a single wrapper. A tag array of two values becomes two tag elements side by side. If the receiving system expects a wrapper, add it in your JSON as a parent key holding the array.

Why did one of my key names change during conversion? XML element names cannot contain certain characters and cannot start with a digit. Keys that break those rules are renamed: invalid characters are replaced with underscores and a digit-leading key gets an underscore prefix. The data is unchanged, but the name is.

What happens to a null value when I convert JSON to XML? It becomes an empty element with no content. Nothing is lost in the conversion, but a reader may interpret an empty element as missing data, so check null fields deliberately after converting.

Can the converter match the exact XML format my system expects? The converter produces one consistent dialect based on fixed mapping rules. If your system follows a specific schema, compare the output against it and adjust the result, because the converter does not reshape its output per schema.

Conclusion

None of these mistakes are conversion errors. The converter applied its rules exactly as documented; the input was not shaped for them. Shape first, convert second, check names and empty elements third, and the output stops being surprising. For the shaping job worked end to end, see our companion guide on converting a JSON feed into an XML sitemap format. For more guides in this series, see our Data and JSON Tools guides.

References