Edit online

Oxygen XML Editor includes a useful and simple tool for converting XML files to JSON. It can be found in the Tools menu.

To convert an XML document to JSON, follow these steps:

  1. Select the XML to JSON action from the Tools menu. The XML to JSON dialog box is displayed:
    Figure 1: XML to JSON Dialog Box
  2. Choose or enter the Input URL of the XML document.
  3. Choose the path of the Output file that will contain the resulting JSON document.
  4. Select the Open in Editor option to open the resulting JSON document in the main editing pane.
  5. Click the Convert button.

The original XML document is now converted to a JSON document.

Figure 2: Example: XML to JSON Operation Result

Conversion Details

  • If any elements contain attributes in the XML document, the attributes are converted to properties in the converted JSON document. If the XML document contains more than one element with the same name, they will be converted into an array of object in the converted JSON document.
    For example, the following XML document:
    <personnel>
      <person id="person.one">
        <name>Boss</name>
      </person>
      <person id="person.two">
        <name>Worker</name>
      </person>
    </personnel>
    it is converted to:
    {
      "personnel": {
        "person": [
          {
            "id": "person.one",
            "name": "Boss"
          },
          {
            "id": "person.two",
            "name": "Worker"
          }
        ]
      }
    }
  • If the XML document contains elements with mixed content (text plus elements), the converted JSON document will contain a content property with its value set as the text content.
    <person>
      <name>Boss <i>One</i></name>
    </person>
    is converted to:
    {
      "person": {
        "name": {
          "content": "Boss",
          "i": "One"
        }
      }
    }
  • If the XML document contains element names that contains hexadecimal codes (for example, if they were escaped during a JSON to XML conversion), it will be converted to the normal character value in the converted JSON document.
    <_X24_id>personnel-id</_X24_id>
    is converted to:
    {"$id": "personnel-id"}

Online XML to JSON Converter

For a simple ONLINE tool for converting a single XML file to JSON, or vice versa, go to: https://www.oxygenxml.com/xml_json_converter.html.