About ReqBin Online JSON to XML Converter
ReqBin Online JSON to XML Converter turns a JSON string into XML in a two-pane view: the JSON source stays on the left, the generated XML appears on the right. The conversion runs in your browser, so the JSON never leaves your machine.
- Convert JSON to XML in one click
- JSON and XML syntax highlighting
- Invalid JSON is reported instead of converted
- Copy either pane with one button
- Upload a JSON file from your disk
- Share a conversion by link, no account needed
- Works in Chrome, Firefox, Safari, and Edge
What is JSON?
The JavaScript Object Notation (JSON) is a lightweight, language-independent, text-based format for exchanging data between two devices and for client-server communication. JSON defines a small set of rules for the portable representation of structured data. JSON can represent four primitive types (strings, numbers, boolean values, and null) and two structured types (objects and arrays). Using JSON, it is possible to exchange data between applications written in various programming languages, including JavaScript, Java, C++, C#, Go, PHP, Python, and many others. JSON files have the extension *.json.
What is XML?
The XML (eXtensible Markup Language) is an extensible markup language. Designed to be a language with a simple formal syntax that facilitates the creation and manipulation of documents by both computer programs by humans. XML is used where a document must carry its own structure: attributes, namespaces, and a schema a parser can validate against. The extensible nature of XML means that you can create markup tailored to the needs of your application and limited only by the language's syntax rules. XML documents can contain comments, declarations, elements, and XML processing instructions. All of these elements in a document are structured using XML markup. XML files have the extension *.xml.
How do I convert JSON to XML online?
- Paste your JSON into the left input box
- Press the Convert button
- Read the XML in the right pane
If the input is not valid JSON, the right pane reads "Invalid JSON string" and no XML is produced. To go the other way, use the XML to JSON converter.
What are the JSON to XML conversion rules?
- An object key becomes an XML tag, and its value becomes the tag's text.
- A nested object becomes a nested element.
- An array becomes repeated sibling elements sharing the array's key:
{"items":[1,2,3]}becomes<items>1</items><items>2</items><items>3</items>. - A null value becomes an empty tag:
{"a":null}becomes<a/>. - Numbers and booleans become text. XML elements have no type, so
125and"125"produce the same element.
What JSON does not convert to valid XML?
XML naming rules are stricter than JSON's, so some JSON produces output that no XML parser will accept. Three cases:
- More than one top-level key.
{"Id":125,"Customer":"Leo"}produces<Id>125</Id><Customer>Leo</Customer>— two root elements, and XML allows one. Output like this is also left unindented, because the converter only reformats what parses as XML. Wrap the object in a single key first:{"Order":{"Id":125,"Customer":"Leo"}}. - Keys that are not valid XML names. A key holding a space becomes
<my key>; a key starting with a digit becomes<1st>. Neither parses. Rename the key before converting. - An array at the top level.
[1,2,3]produces<0>1</0>and so on, and a tag name cannot start with a digit. Put the array under a key.
Converting back is not a round trip. {"Order":{"Id":125}} becomes <Order><Id>125</Id></Order>, and running that through the XML to JSON converter returns {"Order":{"Id":{"_text":"125"}}}: the number is a string now, and each value carries a _text wrapper. The structure survives; the types do not.
What is the difference between JSON and XML?
Both carry structured data as text. The difference is what each format can express, and that is what decides how much survives the conversion above.
- Types. JSON has string, number, boolean, and null. An XML element holds text; types come from a schema, when there is one.
- Arrays. Native in JSON. In XML they are repeated elements by convention, so a one-item array and a plain value look identical.
- Attributes. XML puts them on any element. JSON has none; every value hangs off a key.
- Comments. XML allows them. JSON does not.
- Namespaces. XML has them. JSON does not.
- Schema. XSD or DTD for XML, JSON Schema for JSON. Optional in both.
- Parsing in the browser.
JSON.parsefor JSON,DOMParserfor XML.
JSON is smaller on the wire and maps onto objects in most languages without a library. XML carries markup JSON has no place for: attributes, comments, namespaces, and processing instructions. That is why the round trip above returns a different string from the one you started with. See JSON vs XML for the longer comparison.