Skip to content
JSON & DATA TOOLS

XML to JSON Converter Online

Convert XML elements and attributes into JSON.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

XML to JSON Converter

About XML to JSON Converter

This tool parses XML with your browser's own XML parser and writes the structure as JSON. Child elements become object keys, attributes are kept with an @ prefix, and a tag that repeats under the same parent becomes an array.

It is handy when a legacy service, an RSS feed or a SOAP response returns XML and your code or API expects JSON. Invalid XML is reported as an error, so you know the document is well formed before you use the result.

How to use XML to JSON Converter

  1. Paste a complete XML document with a single root element.
  2. Click Run Tool to convert it.
  3. Copy the JSON, or correct the XML if an error is shown.

Example

Input

<user id="7"><name>NHP Learning</name><active>true</active><tag>php</tag><tag>json</tag></user>

Output

{
  "user": {
    "@id": "7",
    "name": "NHP Learning",
    "active": "true",
    "tag": [
      "php",
      "json"
    ]
  }
}

Common uses

  • Reading an RSS or sitemap XML file as JSON in a script.
  • Converting a legacy API response so a modern front end can use it.
  • Inspecting the structure of an XML document in a more compact form.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Are numbers and booleans converted?

Text content is kept as strings, for example "true" or "25", because XML has no native types. Convert them in your code if you need numbers.

How are attributes represented?

An attribute named id on an element is written as a key called @id inside that element's object.

What if the XML has mixed content?

Elements that contain only text become strings. Elements that mix text and child tags keep the child structure and drop the loose text.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.