Convert XML to JSON

Turn XML files into JSON. The root element becomes the top key; attributes become keys starting with @, repeated elements become a list while a lone one stays a single value, and text beside child elements goes under #text.

Converted in an isolated sandbox on our serversDeleted after 24 hours

Drop XML files on the dialor turn it to pick what to do

XML as JSON data you can read in code.Elements become keys, attributes get an @ prefix, and every value stays text.

  1. What you get

    One JSON file. The root element becomes the top key, and the elements inside it become keys below it.

    Attributes become keys that start with @. When an element has text beside child elements, that text goes under #text.

  2. How the structure maps

    Repeated elements become a list. An element that appears once stays a single value, so the same element can be a list in one file and a single value in another.

    Every value stays text, so a number in the XML comes out as a string in the JSON. An empty element becomes null.

  3. What gets left behind

    Comments and processing instructions are dropped. The position of text between child elements is lost too, because the text is gathered under #text instead of staying between the children.

    To go the other way, use JSON to XML.

  4. When it stops

    If the file cannot be parsed, the conversion stops with input_corrupted. No JSON file is produced in that case.

XML and JSON.What each format is.

The formats

From · XML

XML

XML documents and data.

Extensions
.xml
MIME type
application/xml
Kind
Text and data
To · JSON

JSON

JSON, the data format of every API.

Extensions
.json
MIME type
application/json
Kind
Text and data

In your code.The same XML to JSON conversion through the API, for your app or your agent.

terminal
$ cv convert report.xml report.json
$ cv convert report.xml report.json

Questions.What people ask about XML to JSON.

01OF 04

The root element becomes the top key. Attributes become keys starting with @, and child elements become keys below their parent.

No. Every value stays text, so a number in the XML is a string in the JSON.

Repeated elements become a list. A lone element stays a single value.

No. Comments and processing instructions are lost in the conversion.

More conversions.Other ways in and out of XML and JSON.