FormatterHQ

XML to JSON Schema Generator

Infer a JSON Schema from an XML sample. It describes the JSON form of your XML: attributes and child elements as properties, repeated elements as arrays.

Input XML
Output JSON
Ready.

How to use the XML to JSON Schema

  1. Paste your XML document into the Input editor, or use Sample, Upload file or Load URL.
  2. Leave Top-level class name empty to use the root element name for the root definition, or enter your own.
  3. Press Generate to infer the schema.
  4. Use Copy or Download to save the JSON Schema.

XML to JSON Schema: describing XML data as JSON

Many systems receive XML but store or forward it as JSON: integration platforms, API gateways and message queues often convert between the two. This XML to JSON Schema generator infers a schema for that JSON form. It first maps your XML to objects (attributes and child elements become properties, element text beside attributes becomes value, repeated elements become arrays) and then derives a draft-06 JSON Schema from the result.

Example

<invoice number="INV-2026-001" currency="EUR">
  <customer>Acme GmbH</customer>
  <line sku="A1" qty="2">12.50</line>
  <line sku="B7" qty="1">99.00</line>
  <paid>false</paid>
</invoice>
"Invoice": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "customer": { "type": "string" },
        "line": { "type": "array", "items": { "$ref": "#/definitions/Line" } },
        "paid": { "type": "boolean" },
        "number": { "type": "string" },
        "currency": { "type": "string" }
    },
    "required": ["currency", "customer", "line", "number", "paid"]
},
"Line": {
    "properties": {
        "value": { "type": "number" },
        "sku": { "type": "string" },
        "qty": { "type": "integer" }
    }
}

The amount in each <line> is element text next to attributes, so it appears as value; 12.50 was recognized as a number and qty as an integer. The schema describes JSON, so the distinction between attributes and elements is not preserved.

JSON Schema vs. XSD

If you need to validate the XML itself, the native tool is an XML Schema (XSD) or a RELAX NG schema, which can express attributes, element order, namespaces and mixed content. JSON Schema cannot describe those XML-specific features, but it is the better fit when the data will travel as JSON after conversion:

XSDJSON Schema from this tool
ValidatesThe XML documentThe JSON form of the data
Attributes vs. elementsDistinguishedBoth become properties
Element orderCan be enforcedNot represented
NamespacesSupportedPrefixes removed

Review before use

  • Text that looks like a number or boolean is typed that way; codes with leading zeros should be changed to "type": "string".
  • An element that appears once in the sample is typed as an object; if it can repeat, it should be an array. Include two occurrences to get this right.
  • additionalProperties: false rejects unexpected keys; relax it if your XML may gain new elements.

To see the JSON the schema describes, convert your document with XML to JSON, and check the XML first with the XML Validator. For JSON input, use JSON to JSON Schema. All processing happens in your browser.

Validating converted data with the schema

Once your integration converts incoming XML to JSON, the schema can check each message before it is stored or forwarded. Two common setups:

  • JavaScript: Ajv 8 validates draft-06 schemas after you register the meta-schema with ajv.addMetaSchema(require("ajv/dist/refs/json-schema-draft-06.json")).
  • Python: jsonschema.Draft6Validator(schema).validate(data) raises an error that names the failing property.

Make sure the XML to JSON step uses the same mapping rules as this generator, with attributes as plain properties and text beside attributes in value. A converter that prefixes attributes with @ or stores text as #text produces different property names, and every message would fail validation.

Frequently asked questions

Can this JSON Schema validate my XML file?
No. It validates the JSON representation of the data. To validate XML directly, use an XSD or RELAX NG schema with an XML validator.
How are XML attributes represented in the schema?
As ordinary properties of the element’s object, next to properties for child elements. Text of an element with attributes becomes a value property.
Which draft of JSON Schema is produced?
Draft-06, which common validators such as Ajv support.
Why is a repeating element described as an object?
The sample contained only one occurrence. Add a second one so it is detected as an array.

Last updated September 26, 2026

Related tools