XML to JSON Schema Converter

Paste an XML sample or an XSD, get a draft-07 JSON Schema

Input XML

JSON Schema Output

Paste your XML on the left and the JSON shows up here.

Or drop a file on this box, , or .

What is XML to JSON Schema Converter?

This tool turns an XML document, or an XML Schema (XSD), into a JSON Schema draft-07 document. The schema describes the JSON shape our XML to JSON converter produces: attributes as @name properties, an element's own text as #text, repeated elements as arrays. That makes it handy when an XML feed is being turned into JSON and you want to validate the result, as described at json-schema.org.

For a plain XML sample, the schema is inferred from every instance of each element: a property lands in required only if all of them carry it, and its type follows the values, so qty becomes integer, price becomes number, giftWrap becomes boolean, and a zip such as 02134 keeps the whole field a string. For an XSD it reads global and inline xs:element, xs:complexType and xs:simpleType declarations, sequences, choices, attributes, simple content, minOccurs/maxOccurs, enumerations and the common facets. The XML is read with the DOMParser built into your browser, and the schema is assembled in the page with no server call.

How to Convert XML to JSON Schema

Follow these steps to generate a JSON Schema from your XML.

1

Paste or Upload XML

Put an XML document or an XSD in the Input XML panel, or pick a file with Upload. An XSD is recognised by a schema root in the http://www.w3.org/2001/XMLSchema namespace, whether the prefix is xs: or xsd:. Sample loads two orders so you can see how optional fields and arrays are handled.

2

View Generated Schema

The JSON Schema Output panel updates as you type. In the sample, giftWrap shows up as an optional boolean because only one item has it, and zip stays a string because 02134 starts with a zero.

3

Download or Copy

Download saves the result as schema.json, ready to hand to Ajv or any other draft-07 validator; Copy grabs it for pasting into your repo or API spec.

When You'd Actually Use This

API Documentation

Convert your XML data structures to JSON Schema to document your REST API request and response bodies using tools like OpenAPI / Swagger.

Data Validation Setup

Generate a JSON Schema from sample XML to use as a validation baseline for JSON data that mirrors your XML structure.

Schema Migration

Moving from SOAP and XSD to JSON APIs? Paste the XSD to get a starting JSON Schema, with named complex types under definitions and enumerations kept as enum.

Code Generation

Use the generated JSON Schema as input to code generators that produce TypeScript interfaces, Java classes, or models in other languages.

Frequently Asked Questions

Is the XML sent to a server?

No. The XML or XSD is parsed and turned into a schema inside this page, and no request carries it to a server. Files above 5 MB are refused, but a handful of records is all the inference uses anyway.

Which JSON Schema draft does it generate?

Draft-07, which almost every validator supports, Ajv included. See the draft-07 meta-schema.

What does it do with XML attributes?

Each attribute becomes an @name property with a type inferred from its values (or from its declared type in an XSD), and is required when every instance has it or the XSD says use="required".

How does it detect arrays?

From a sample, an element becomes an array when it repeats inside at least one parent. From an XSD, when maxOccurs is greater than 1 or unbounded; minOccurs and maxOccurs become minItems and maxItems.

What parts of XSD are supported?

Global and inline complex and simple types, xs:sequence, xs:all, xs:choice (choice branches are optional), element refs, attributes, simple content with attributes, complex content extension (as allOf), enumerations, patterns, length and range facets, and documentation annotations. Imports, includes, substitution groups and identity constraints are not processed. If you need the exact rules behind any of those constructs, they are defined in XML Schema Part 1: Structures.

Will the schema be exactly right?

From an XSD it is close; from a sample it is only as good as the sample. A field that happens to be present in every record of your sample is marked required, so review the required lists before you rely on them.

Related Tools

Explore other XML and schema tools: