XML still sits behind RSS feeds, SOAP services, sitemaps and many enterprise exports, while most modern code expects JSON. The Kwebby XML to JSON Converter turns pasted XML into formatted JSON in your browser, so a feed or a config file becomes something your JavaScript can read.
It converts in one direction only, XML to JSON. This page shows exactly how it maps tags, attributes and text, and where the result can surprise you.
Key Takeaways
- Kwebby's XML to JSON Converter turns XML into pretty-printed JSON as you type, using your browser's own XML parser. It converts XML to JSON only.
- Attributes become keys with an @ prefix, repeated tags become arrays, and text that sits beside attributes or child elements goes under #text.
- A tag that appears once becomes an object, but the same tag appearing twice becomes an array. Write code that handles both shapes.
- Every value comes out as a string, so convert numbers and booleans yourself.
- Comments are dropped. CDATA text is kept as plain text, and text mixed with child tags is joined with single spaces, so its position next to the tags is lost.
- Invalid XML shows a "Parse error" message instead of JSON.
What Is the Kwebby XML to JSON Converter?
Kwebby's XML to JSON Converter is a free online tool that turns XML into formatted JSON. You paste XML into the Input XML box and the Output JSON box fills in at once, using your browser's own XML parser. It handles attributes, nested elements and text, and your XML is not uploaded.
There are two buttons besides the boxes: Copy puts the JSON on your clipboard and Clear empties the input. The tool does not turn JSON back into XML.
Key Features and How It Works
Conversion as you type, in your browser
The tool uses the browser's built-in DOMParser to read your XML. If the XML is not well formed, MDN explains that the parser returns a document containing a parsererror node instead of throwing an error. Kwebby shows that message after the words "Parse error:" so you can find the broken tag.
Attributes become @ keys
An attribute such as id="1" becomes a key named @id. The prefix keeps attributes apart from child elements that happen to share a name. Converters disagree here: some use @_, a hyphen or an @attributes object. If your code expects another convention, rename the keys after converting.
Repeated tags become arrays
When the same tag appears more than once under one parent, the converter groups the copies into an array. A tag that appears once stays a single object. That keeps the output compact, but the JSON shape then depends on how many items the XML happens to hold.
Text next to attributes or children goes under #text
An element with only text becomes a plain string. An element with text and attributes becomes an object, with the text under #text. An empty element becomes null. So <price currency="USD">9.99</price> becomes an object with @currency set to "USD" and #text set to "9.99".
Readable output with Copy and Clear
The JSON is indented with two spaces so you can read it. The Copy button shows a tick when it has copied the result, and Clear empties the input box so you can start again.
A worked example
This XML is the sample the page shows:
<users>
<user id="1">
<name>Alice</name>
<age>30</age>
</user>
</users>
It becomes:
{
"users": {
"user": {
"@id": "1",
"name": "Alice",
"age": "30"
}
}
}
The root tag is the top-level key, the attribute is @id, and age is the text "30", not the number 30. With two user elements, user would become an array of two objects.
Why Converting XML to JSON Matters
JSON is a lightweight, text-based data format. RFC 8259 defines it with objects, arrays, strings, numbers, true, false and null, and it has no attributes or comments. XML supports attributes, comments, namespaces and mixed content, so a converter has to decide how to represent each of them. That is why the same XML gives slightly different JSON in different tools.
XML is not going away. Feeds, SOAP services, office file formats and many configuration files still use it. New web APIs mostly use JSON, and JavaScript reads it natively with JSON.parse(). A converter bridges the two, so you can use legacy or third-party XML in a modern codebase without writing a parser.
How to Use the XML to JSON Converter
- Prepare your XML. Check that it has one root element and that every tag is closed. Escape
&and<inside text. - Paste it into Input XML. The box shows a small users example when it is empty.
- Read the Output JSON. The result appears as you type. If you see "Parse error", fix the XML it points to.
- Check the shape. Look for the
@keys, the#textkeys and which tags became arrays. - Click Copy. Paste the JSON into your code or API client, and click Clear to start the next conversion.
Best Practices for XML to JSON Conversion
Make sure the XML is well formed
The parser is strict. Close every tag, use a single root element and escape special characters. The HTML Encoder / Decoder converts characters such as ampersands and angle brackets into safe entities.
Handle both object and array shapes in code
Common mistake: assuming a repeated tag is always an array. With one item you get an object, with two you get an array. In your code, test with Array.isArray() and wrap a single object in an array before looping.
Convert numbers and booleans in your code
Every value is a string. Parse numbers and true or false values where you use them, and keep codes such as ZIP codes with leading zeros as text.
Be careful with mixed content
Text mixed with inline tags, such as Hello <b>bold</b> world, does not survive intact. The text pieces are trimmed and joined with a space under #text ("Hello world"), and the b element becomes its own key, so the original order is lost. For HTML-like documents, use a full XML library instead.
Know what is dropped
Comments are ignored. The text inside a CDATA section is kept as an ordinary string, without the CDATA markers. Namespaces are kept as written, for example a dc:title key and an @xmlns:dc attribute. Review the output if your XML relies on any of these.
Compare before and after
For an important conversion, run the output through the Diff Checker against an earlier version to see exactly what changed.
Use a library for repeatable pipelines
For scheduled jobs and large files, libraries such as xmltodict for Python or xml2js for Node give you options and control over the mapping. The online tool is best for one-off conversions and for checking what a library should produce.
Common Use Cases
- RSS and Atom feeds. Turn a feed into JSON for a JavaScript app or a prototype.
- SOAP responses. Make a verbose XML response easier to read and test.
- Configuration files. Convert an XML config into JSON for a Node.js project.
- Sitemaps. A sitemap is XML with one
urltag per page, so it makes a good test. Create one with the XML Sitemap Generator and convert it to inspect the URL list. - Spreadsheet and XML data side by side. Convert tabular data with the CSV to JSON converter and compare the shapes.
- Learning. See how a tag, an attribute and a text node map to JSON keys.
Related Kwebby Tools
More data tools live in the Developer Tools hub:
- CSV to JSON converts CSV data to JSON objects and JSON arrays back to CSV.
- Diff Checker compares two texts, such as two JSON outputs, and shows the differences.
- XML Sitemap Generator creates a sitemap file, a common source of XML.
- HTML Encoder / Decoder escapes and unescapes special characters before you convert.
Frequently Asked Questions (FAQs)
How do I convert XML to JSON?
Paste your XML into the Input XML box of Kwebby's converter and read the JSON in the Output JSON box. Make sure the XML has a single root element and closed tags. Click Copy to use the result.
Can the Kwebby converter turn JSON back into XML?
No. The tool converts XML to JSON only. For the reverse direction you need a separate JSON to XML tool or a library in your own code.
How does the converter handle XML attributes?
Each attribute becomes a key with an @ prefix, so id="1" becomes @id. If the element also has text, the text is stored under #text. Other tools use different prefixes, so rename the keys if your code expects another style.
Why is one element an object but several elements an array?
The converter groups repeated tags into an array and leaves a single tag as an object. This keeps the JSON short, but the shape changes with the data. In your code, check with Array.isArray() and wrap a single object in an array.
Is it safe to paste private XML into the converter?
The conversion runs in your browser, and the page's script makes no network request with your XML. Even so, avoid pasting secrets such as keys or personal data into any online tool, and test with a sample when you can.
Is the Kwebby XML to JSON Converter free?
Yes. The tool is free and needs no account.
Final Thoughts
Converting XML to JSON is straightforward once you know the mapping: @ for attributes, #text for mixed text, arrays for repeats and strings for every value. Kwebby's converter gives you that mapping instantly, and your code decides what types and shapes to enforce.
Paste a sample of your XML into the converter and check the output against what your app expects. If your data starts as a spreadsheet, try CSV to JSON, or browse the full Kwebby tools list.