XSD to JSON Schema Converter
: Convert supported XML Schema declarations to JSON SchemaXSD to JSON Schema Converter
Translate a supported XML Schema into a JSON Schema draft 2020-12 document for a defined JSON representation. Element declarations become properties, attributes use an @ prefix, and repeated elements become arrays. Conversion stops on unsupported constructs so a choice, import or pattern does not quietly disappear from the result.
How to convert XSD to JSON Schema
- Paste your XSD into the
XSD schemapane, select it withOpen file, or pressExamplefor an order declaration. - The JSON Schema appears as you type; a schema over 2,000,000 characters waits for the
Convertbutton instead and shows its progress, withCancel. If a feature is unsupported, resolve the issue named in the message above the panes; no partial output is shown. - Read any warnings above the panes (types mapped loosely, mixed text) and the JSON representation note under them. Your JSON data must use that representation to match the generated schema.
- Use
CopyorDownloadto save the JSON Schema, then validate representative JSON documents against it.
Example
A required identifier becomes @id. Tags are optional, but when present they use an array even if there is only one tag. The document is wrapped under order.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="tag" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$comment": "Wrap the root in an object. Element names use {namespaceURI}localName when qualified; unqualified names stay plain. Attributes use @name (or @{namespaceURI}name). Simple elements are typed JSON values. Elements with attributes use an object with #text. Repeated elements are always arrays. Optional properties may be absent. XML order and namespace declarations are not represented.",
"type": "object",
"properties": {
"order": {
"$ref": "#/$defs/element:order"
}
},
"required": [
"order"
],
"additionalProperties": false,
"$defs": {
"element:order": {
"type": "object",
"properties": {
"tag": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 0
},
"@id": {
"type": "string"
}
},
"required": [
"@id"
],
"additionalProperties": false
}
}
}Details
- The example accepts JSON such as
{"order":{"@id":"A1","tag":["gift"]}}. Simple elements map to typed JSON values. An element with attributes and simple text uses an object with a required#textproperty. Mixed content uses optional#text; its position among children is lost. - Qualified names use
{namespaceURI}localNameas the property name, and qualified attributes use@{namespaceURI}localName. Unqualified names stay plain. Namespace declarations themselves are not JSON properties. These rules may differ from the output of other XML-to-JSON converters. - Supported declarations include named types, same-document element references, flat sequence/all groups, attributes and simpleContent extensions with built-in bases. Repeated elements carry minItems and finite maxItems; required properties follow minOccurs or attribute use. Objects reject undeclared properties.
- Simple restrictions support enumeration, length, minLength and maxLength (on string-like bases, where XSD counts characters) and inclusive/exclusive numeric bounds with built-in bases. Length facets on
xs:hexBinaryorxs:base64Binary(which count bytes) and an enumeration onxs:boolean(which XSD does not allow) stop the conversion. Named and recursive references use$defs. Multiple global elements produceoneOfalternatives for the document root. - Dates (including partial dates such as
xs:gYear), token types, binary strings and several other XML scalar types become strings with warnings because their lexical or identity constraints are not reproduced. JSON numbers use JavaScript precision; review large integers and decimal values.
Limits
- This is a subset converter, not a complete XSD validator. Validate the source schema separately. The resulting JSON Schema validates JSON values, not the original XML or XML child order.
- Imports/includes, choices, nested or repeated groups, complexContent inheritance, lists/unions, pattern facets, wildcards, identity constraints, defaults/fixed values, nillable and XSD 1.1 features are rejected. Restrictions of named simple types and simpleContent extensions of named types are also unsupported. So are types a JSON number cannot hold exactly (
xs:double,xs:float,xs:long,xs:unsignedLong),xs:QName, the list types (xs:IDREFS,xs:NMTOKENS,xs:ENTITIES) and an element with no type (xs:anyType). - Large schemas work, with no limit on characters or elements; opened files allow 50 MB. XML nesting and reference nesting are limited to 64 levels. DTDs and custom entities are rejected.
FAQ
Can this convert any XSD without losing constraints?
No. XML and JSON have different models, and this converter handles a declared subset. Unsupported structures stop conversion. Constraints intentionally mapped more loosely, such as date lexical rules and mixed-text ordering, produce warnings.
Do I need to keep the XML root name in my JSON?
Yes. The generated schema expects an object containing exactly one declared root property. A target namespace is included in that property's name using the {namespaceURI}localName convention.
Runs entirely in your browser. Nothing is uploaded.