Every long-lived application accumulates a config file, and a lot of them are still XML: server settings, logging levels, feature flags, connection details. Then the tooling around the app moves to JSON, and someone has to turn the old file into a settings object without retyping it and without guessing what the conversion did to each value.
That conversion is mechanical, but the result is not always the shape you expect. Attributes change their names, repeated blocks change their type, and numbers come out as text. This guide walks through converting an XML config file with the free XML to JSON Converter on Ovatly, explains each rule the converter applies, and shows a worked example so you can predict the output before you run it.
Contents
- Quick answer
- Why config files end up as JSON
- The rules the converter applies
- How to convert XML config data, step by step
- Worked example: a small server config
- After conversion: the @ key decision
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Paste your XML config into the XML to JSON Converter and convert. Attributes become keys starting with @, an element holding only text becomes a plain value, and a block that repeats becomes an array. Copy the JSON into your settings file, then make one decision: keep the @ keys as they are, or rename them in your own editor so your code reads plain names. Renaming is your edit after conversion, not something the tool does. Expect every value to stay a string, and expect comments from the XML to be left behind.
Why config files end up as JSON
XML was the default config format for a generation of software, so plenty of running systems still keep their settings in it. Newer tooling tends to speak JSON: it is the format APIs return, the format most web frameworks read natively, and the format developers already have open in their editors.
When a system is migrated, wrapped or simply maintained by new tools, the config has to follow. Hand-copying a large config is slow and error-prone: one missed element or transposed value can change how the application behaves. A converter does the mechanical part exactly, and your job becomes checking the result against the rules below rather than proofreading hundreds of lines.
The rules the converter applies
The converter parses your XML with the DOMParser built into your browser and rebuilds it as JSON using a small set of rules. Knowing them means nothing in the output surprises you.
Attributes become @ keys. An attribute on an element becomes a key prefixed with @, sitting in an object beside the element's children. A host attribute on a <server> element becomes the key @host. The prefix keeps attributes distinct from child elements that share a name.
Text-only elements become plain values. If an element holds text and nothing else, it becomes a string value under its own name. A <logging> element containing the word info becomes a logging key with the value info.
Text beside attributes gets its own key. When an element has attributes and text together, the text goes under a #text key next to the @ keys, so it is not lost.
Repeated blocks become arrays. If the same element appears several times under one parent, the JSON value is an array of those blocks in order. A block that appears once stays a single object, which is why a config can produce different shapes in different places.
Everything stays a string. Attribute values and element text are carried across as text. A port written as 8080 in the XML arrives as the string 8080 in the JSON. The converter does not guess types.
How to convert XML config data, step by step
- Open the XML to JSON Converter and paste your config XML into the input. The tool never fetches a URL, so paste the file contents rather than a link.
- Run the conversion. If the XML is not well formed, the tool reports the problem in plain words instead of producing partial output; fix the XML and run it again.
- Read the result against the rules above: find the @ keys, check that repeated blocks became arrays, and note which values your code will need to treat as strings.
- Copy the JSON into your settings file, and keep the original XML somewhere safe until the new settings have run in production.
Worked example: a small server config
Take a small server config with an attribute pair, a repeated block and one text-only setting:
<config>
<server host="localhost" port="8080">
<route>/api</route>
<route>/docs</route>
</server>
<logging>info</logging>
</config>
The converter produces this:
{
"config": {
"server": {
"@host": "localhost",
"@port": "8080",
"route": ["/api", "/docs"]
},
"logging": "info"
}
}
Read it rule by rule. The two attributes on <server> became @host and @port, and the port is still the string 8080, not a number. The <route> element appears twice, so route is an array of two strings. The <logging> element holds only text, so it became the plain value info.
After conversion: the @ key decision
The one choice the conversion leaves you is what to do with the @ keys. The converter will not rename them, because the right answer depends on the code that reads the settings.
Keep them if your reader can be written or configured to look for @host and @port. The names are unambiguous, and keeping them means the JSON stays a faithful copy of the XML structure. Rename them if your settings format expects plain names like host and port. Do the renaming once, in your editor or in the code that loads the file, and do it for every @ key, so the settings stay consistent. What you should not do is rename some and leave others: mixed conventions are how settings get silently ignored.
Limitations and honest tradeoffs
Comments and processing instructions are not carried over. Config files often rely on comments to explain why a setting exists. Those explanations stay in the XML only, so keep the original file as documentation even after you switch.
Namespaces are not carried over either. A config that leans on namespace prefixes loses that layer of meaning in the JSON.
Shapes vary with the data. A block that appears once is an object; add a second one later and it becomes an array. Readers that assume one fixed shape will break when the config grows.
Values stay strings. Numbers, booleans and anything else arrive as text, and converting them is the reader's job. The tool converts only what you paste, and it does not know what your application expects.
Common mistakes
- Expecting attributes under their plain names. They are under @ names. Code looking for
hostwill not find@host. - Assuming a block is always an array. A single occurrence stays a single object. Handle both shapes.
- Treating converted values as numbers. The port 8080 arrives as a string. Compare and calculate accordingly.
- Deleting the XML once the JSON works. The comments and the original structure live only there. Keep it.
- Pasting a URL instead of the file. The converter never fetches; paste the XML text itself.
FAQs
What happens to attributes when I convert a config file? Each attribute becomes a key prefixed with @, sitting in the same object as the element's children. The id attribute on a server element becomes the key @id. Attribute values stay strings, so a port written as an attribute arrives as text, not as a number.
Should I keep the @ keys or rename them? That is your decision, and it happens after conversion, not inside the tool. Keep them if your code can read them as they are. Rename them if your settings format expects plain names, and do it once, in one place, so the rest of your code sees a consistent shape.
Why did one setting become an array and another stay a single object? Repeated elements become arrays, and a single occurrence stays single. If a block appears twice in the XML it is an array in the JSON; if it appears once it is a plain object. Code that reads the settings has to allow for both shapes.
Do numbers in my config stay numbers? No. Element text and attribute values stay strings in the JSON, so a value like 8080 arrives as text. If your application needs a real number, it converts the string when it reads the setting.
Is my config file uploaded anywhere? No. The converter runs fully in your browser using the DOMParser, and it never fetches a URL. You paste the XML in yourself, and the text never leaves your device.
Conclusion
Converting a config file is a mechanical job with a short list of rules: attributes gain an @ prefix, text-only elements become plain values, repeated blocks become arrays, and every value stays a string. Run the XML to JSON Converter, check the output against those rules, and make the @ key decision once, deliberately. For the attribute rule in more depth, see What Happens to XML Attributes When You Convert to JSON. More converters and their guides live in our Data and JSON Tools guides.
References
- MDN Web Docs, DOMParser, the browser parser the converter is built on: https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
- MDN Web Docs, Working with JSON: https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/JSON