XML to JSON Converter
Convert XML documents and fragments into formatted JSON text while preserving attributes, element hierarchy, and custom array mappings.
Run tool
This online XML to JSON converter translates structured XML snippets into clean JSON text. It maps tag hierarchies to nested JSON objects while retaining XML attributes and element text content accurately. When an XML document contains repeated sibling tags under the same parent element, the converter automatically bundles those repeated entries into JSON arrays. If you have single elements that your data schema requires as arrays, specify those tag names in the dedicated list setting separated by commas. You can also adjust the indentation spacing to match your preferred indentation style, such as two spaces, four spaces, or compact formatting. Submitting blank or whitespace-only input yields an empty JSON object. If the source XML is malformed or contains unclosed tags, the tool displays an error message indicating the syntax issue instead of generating invalid output. After conversion, the formatted JSON output appears in the result area, ready for use in modern web APIs, legacy configuration file migration, or XML schema inspection inside JSON-oriented workflows.
Instructions
- Paste or type your XML markup into the XML Input field.
- Set your desired numeric indentation spacing, which defaults to two spaces.
- Optionally enter comma-separated tag names into the Force List field to ensure specific elements always output as arrays.
- After running the conversion, the formatted JSON output appears in the result area.
Examples
- Converting <user id="101"><name>Alex</name><role>Admin</role><role>Editor</role></user> with default 2-space indentation yields a JSON object with user attributes and an array for the repeated role tags.
- Converting <catalog><item id="1"><title>Notebook</title></item></catalog> with the Force List field set to item outputs the single item element as an array inside the catalog object.
FAQ
How does the converter handle XML tag attributes?
Attributes attached to XML elements are preserved and represented directly as properties inside the corresponding JSON objects.
What happens when an XML element repeats multiple times?
When multiple child elements share the same tag name under a single parent, the converter automatically groups them into a JSON array.
How do I ensure a single element appears as an array in JSON?
Enter the element tag name into the Force List field. If you have several elements to treat as lists, separate their names with commas.
What happens if the input XML contains syntax errors?
If the input XML is malformed or contains unclosed tags, the tool displays an error message indicating the syntax issue instead of generating invalid output.