JSON → XSD

JSON to XML Schema (XSD) Definition Generator

Infer XML Schema Definition (XSD) type structures, complex elements, attributes, and minOccurs/maxOccurs rules from sample JSON.

Design Pattern
JSON Input Document
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="https://schema.toolsaa.com/v1"
  xmlns="https://schema.toolsaa.com/v1"
  elementFormDefault="qualified">

  <!-- Top-Level Root Element Declaration -->
  <xs:element name="purchaseOrder" type="PurchaseOrderType"/>

  <!-- Reusable Global Complex Types (Venetian Blind Pattern) -->
  <xs:complexType name="PurchaseOrderType">
    <xs:sequence>
      <xs:element name="orderDate" type="xs:dateTime"/>
      <xs:element name="deliveryDate" type="xs:date"/>
      <xs:element name="status" type="xs:string"/>
      <xs:element name="customer" type="CustomerType"/>
      <xs:element name="lineItems" type="LineItemsType" maxOccurs="unbounded"/>
      <xs:element name="paymentSummary" type="PaymentSummaryType"/>
    </xs:sequence>
    <xs:attribute name="orderNumber" type="xs:string" use="required"/>
    <xs:attribute name="currency" type="xs:string" use="required"/>
    <xs:attribute name="version" type="xs:string" use="required"/>
  </xs:complexType>

  <xs:complexType name="CustomerType">
    <xs:sequence>
      <xs:element name="id" type="xs:string"/>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="email" type="xs:string"/>
      <xs:element name="vatNumber" type="xs:string"/>
      <xs:element name="isTaxExempt" type="xs:boolean"/>
      <xs:element name="addresses" type="AddressesType" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="LineItemsType">
    <xs:sequence>
      <xs:element name="sku" type="xs:string"/>
      <xs:element name="description" type="xs:string"/>
      <xs:element name="quantity" type="xs:int"/>
      <xs:element name="unitPrice" type="xs:decimal"/>
      <xs:element name="taxRate" type="xs:decimal"/>
      <xs:element name="inStock" type="xs:boolean"/>
      <xs:element name="tags" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="PaymentSummaryType">
    <xs:sequence>
      <xs:element name="subtotal" type="xs:int"/>
      <xs:element name="taxTotal" type="xs:decimal"/>
      <xs:element name="shippingFee" type="xs:int"/>
      <xs:element name="grandTotal" type="xs:decimal"/>
      <xs:element name="paymentMethod" type="xs:string"/>
      <xs:element name="paid" type="xs:boolean"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="AddressesType">
    <xs:sequence>
      <xs:element name="type" type="xs:string"/>
      <xs:element name="street" type="xs:string"/>
      <xs:element name="city" type="xs:string"/>
      <xs:element name="state" type="xs:string"/>
      <xs:element name="postalCode" type="xs:string"/>
      <xs:element name="country" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>
Inferred Schema Elements
27 Elements (3 Unbounded)
Complex & Simple Types
5 Complex, 3 Attributes
W3C XSD Specification
W3C XML Schema 1.0 (Strict AST)
100% Client-Side Privacy

JSON parsing, type inference, and XSD generation run completely inside your browser sandbox with zero network transmission.

Multi-Pattern XSD Architecture

Choose between Venetian Blind (reusable named complex types), Russian Doll (nested anonymous types), or Salami Slice (global element references).

Smart W3C Type Inference

Accurately distinguishes xs:dateTime, xs:date, xs:anyURI, xs:decimal, xs:integer, and auto-detects XML attribute prefixes (@_ and @).

Technical Reference & Architecture Guide

JSON to XML Schema (XSD) Definition Generator Developer Guide — Reference Guide

Infer XML Schema Definition (XSD) type structures, complex elements, attributes, and minOccurs/maxOccurs rules from sample JSON.

Key Parameters & Controls

designPatternstring

W3C XSD structural modeling pattern: 'venetian-blind' (reusable named global complexTypes), 'russian-doll' (nested anonymous types), or 'salami-slice' (all elements declared globally).

Default: venetian-blind
rootElementNamestring

Name assigned to the top-level XML root element declaration in the generated schema.

Default: purchaseOrder
targetNamespacestring

Target URI namespace attribute on xs:schema defining the XML namespace identifier.

Default: https://schema.toolsaa.com/v1
cardinalityRulestring

Strategy for element cardinality: 'auto' (derives minOccurs/maxOccurs from arrays and nulls), 'strict' (enforces minOccurs=1), or 'flexible' (minOccurs=0).

Default: auto
detectAttributesboolean

Automatically maps JSON keys with '@' or '_' prefixes to xs:attribute declarations rather than child elements.

Default: true
detectDateUriboolean

Infers specialized W3C data types including xs:dateTime, xs:date, and xs:anyURI from matching string formats.

Default: true

Pro Tips & Best Practices

Venetian Blind Pattern for Code Generation

Venetian Blind is the industry standard for JAXB (xjc) and .NET xsd.exe code generation because it generates distinct, named classes and structs for every complexType rather than deeply nested anonymous inner classes.

XML Attributes vs. Child Elements

Prefix metadata fields with '@' (e.g., '@id', '@currency', '@version') in your input JSON. This produces clean XML schemas with xs:attribute on the complexType while retaining business data as structured xs:element nodes.

Handling Heterogeneous Arrays and Cardinality

Ensure your JSON sample includes array elements that exhibit all potential optional fields. The inferrer detects arrays and outputs an element declaration with maxOccurs="unbounded" and minOccurs="0".

Namespace Qualification with elementFormDefault

Keep elementFormDefault="qualified" to ensure child elements in XML instances inherit the target namespace. This avoids schema validation errors when consuming payloads across enterprise ESB and SOAP gateways.

Common Gotchas & Troubleshooting

XML instance fails schema validation due to child element ordering

W3C XSD xs:sequence enforces strict element ordering matching the schema. Ensure JSON payloads or XML serialization maintain the identical element sequence, or consider xs:all if unordered elements are required.

ISO timestamps or dates are inferred as xs:string instead of xs:dateTime

Verify your JSON date strings strictly follow ISO 8601 formatting (e.g., '2026-10-16T14:30:00Z' or '2026-10-16'). Non-standard date formats fall back to generic xs:string.

Empty arrays [] or null fields result in empty complex types or xs:anyType

Empty arrays provide no sample items to determine element structure. Populate array fields in your JSON input with at least one representative object containing all expected keys.

Frequently Asked Questions

What is the difference between Venetian Blind, Russian Doll, and Salami Slice design patterns?▼

Venetian Blind defines one global root element and named global complexTypes, optimizing reuse and object-oriented code generation. Russian Doll embeds anonymous complexTypes directly inside elements, which creates a rigid single-purpose hierarchy. Salami Slice declares every element globally, maximizing element reuse at the cost of allowing any element to serve as the document root.

How does the generator distinguish between XML attributes and elements?▼

When detectAttributes is enabled, any JSON object key starting with '@' (e.g., '@orderId') or '_' (e.g., '_type') is mapped to an <xs:attribute> definition on the parent complexType. Standard keys without attribute prefixes are converted to <xs:element> child tags.

Can the generated XSD schema be compiled with Java JAXB (xjc) or C# xsd.exe?▼

Yes. The output conforms 100% to the W3C XML Schema 1.0 recommendation. You can directly run 'xjc -d src schema.xsd' in Java or 'xsd.exe schema.xsd /classes' in .NET to produce strongly-typed domain model classes.

How are primitive JSON values mapped to W3C XSD built-in types?▼

Numbers without decimals are typed as xs:integer (or xs:long for large values), numbers with decimals as xs:decimal, booleans as xs:boolean, and strings matching ISO dates or URLs as xs:dateTime, xs:date, or xs:anyURI. All other text defaults to xs:string.

Is my JSON payload or schema uploaded to any server or processed by external AI?▼

No. The entire AST parsing, type inference engine, and XML/XSD serialization run 100% client-side in your web browser. No data leaves your machine.

Related Tools & Utilities

All Tools →