Guide

How to Convert XML to JSON

Paste well-formed XML, select indentation or forced-list options when needed, and start the conversion. The result is JSON-formatted text that retains XML attributes and structure.

Tool XML to JSON Converter

What the conversion is for

XML to JSON conversion helps when information stored as XML needs to be represented as JSON-formatted text for a configuration task, development workflow, or data exchange. Paste the XML text, choose formatting preferences, and review the converted representation. The conversion retains the XML structure and includes XML attributes in the JSON data. When child elements repeat, they are represented as lists, which keeps repeated records distinguishable instead of reducing them to one value. This makes the result easier to inspect when the source contains nested groups, labelled values, or several entries with the same element name. The tool is intended for XML input and produces JSON-formatted text as its result.

Conversion steps

  1. Paste the XML text into the input area. Review its opening and closing tags, nesting, and attribute syntax before converting, because malformed XML produces an unsuccessful conversion rather than a usable JSON result.

  2. Choose the JSON indentation setting. The default is two spaces, and you can specify the indentation numerically when you want a different presentation for reading or copying the result.

  3. If named elements should use list representation, enter their names as a comma-separated set in the forced-list option. This setting can request list representation for a selected name even when that element occurs once in the supplied XML.

  4. Start the conversion and inspect the JSON-formatted text. Blank input and input containing only whitespace succeed with an empty JSON object representation, so do not confuse that outcome with converted source data. If the parsed data cannot be serialized as JSON, the conversion is unsuccessful. For a useful result, provide XML that contains the information you intend to represent and check the displayed output after conversion.

How to interpret the result

Read the result as JSON-formatted data that follows the source XML hierarchy. Attributes from the XML are represented in the converted data, so inspect the relevant object or entry when you need to confirm an attribute was retained. Repeated child elements appear as lists, giving several entries a shared list representation. A forced-list selection affects the representation of the named elements and can make a single occurrence appear as a list as well.

Indentation changes the visual formatting of the JSON text, not the information expressed by the source structure. A compact setting may help when space matters, while a larger numeric setting may make nested content easier to scan. An unsuccessful conversion does not supply a successful JSON result to interpret. First check the XML structure, then review the selected options and input. A failure may also indicate that the parsed data could not be serialized as JSON, so correcting the source alone may not address every unsuccessful outcome.

Worked example

An order record contains an id attribute and two item elements: BookPen.

Paste the XML, leave the two-space indentation setting selected, and start the conversion.

The JSON data represents the order structure, includes the source id attribute, and represents the two item elements as a list.

Limitations

  • Malformed XML or parsed data that cannot be serialized as JSON leads to an unsuccessful conversion.

Common errors

  • Cause: The submitted XML is malformed, so the conversion ends unsuccessfully. Correction: Check the tag nesting, closing tags, and attribute syntax, then submit a well-formed version before assessing the JSON output.

FAQ

What happens with blank XML input?

Empty or whitespace-only input succeeds and produces an empty JSON object representation. It does not represent records that were not supplied in the input.

How are repeated XML elements represented?

Repeated child elements are represented as lists in the converted JSON data. This keeps several occurrences grouped under their element name.

Why did the XML to JSON conversion fail?

Malformed XML causes an unsuccessful conversion instead of a successful JSON result. Review the source structure and try again with corrected XML.

Tool

XML to JSON Converter