XML to JSONSchema

Generate a JSON Schema describing the JSON form of an XML sample.

XML to JSON Schema – Describe XML data as JSON

The XML to JSON Schema generator infers a schema for the JSON representation of an XML document. This is useful when XML data is converted to JSON somewhere in your pipeline — by an API gateway, an ETL job, or a library like xmltodict — and you want to validate the converted payload with standard JSON Schema tooling.

How XML maps to types

XML has no native types, so the converter reads every element and attribute value and infers one: whole numbers become integers, decimals become floating-point numbers, true/false become booleans, and everything else stays a string. Attributes are kept apart from child elements (they appear as @name keys internally), an element that has both attributes and text gets a dedicated text field, and repeated sibling elements such as several item nodes become a list. Namespace prefixes are stripped from names so ns:customer and customer produce the same type.

What the schema contains

  • type for every property (string, integer, number, boolean, object, array).
  • required lists, computed from which elements appear in every repeated sibling.
  • format hints for ISO dates, date-times, e-mail addresses, URIs and UUIDs found in element text.
  • Attribute properties named @attr and text properties named #text, matching the common XML-to-JSON convention used by the XML to JSON converter on this site.

Pick the draft you need (2020-12, 2019-09 or draft-07), decide whether additionalProperties should be allowed, and copy the result into your OpenAPI components or validator configuration.

XSD or JSON Schema?

If your consumers validate the original XML, an XSD is the right tool. If they receive JSON after conversion, JSON Schema is easier to use from JavaScript, Python and most API platforms. This generator gives you a quick, accurate starting point for the second case.

Tips

Repeated elements are only recognised as arrays when the sample contains at least two of them; add a second item or edit the schema to "type": "array" for single occurrences.

Validate JSON against the result with the JSON Validator or generate a schema from JSON with JSON to JSONSchema.

Frequently Asked Questions

No. The XML is parsed and converted by JavaScript running in your browser tab. Nothing is sent to a server, so internal feeds, SOAP payloads and configuration files stay on your machine.

JSON has no attributes, so the widely used XML-to-JSON convention prefixes attribute names with @ and stores mixed text in #text. The schema follows that convention so it validates the output of xmltodict and similar converters.

No, this tool produces JSON Schema only. It describes the JSON form of your XML, which is what most modern API tooling validates.

Draft 2020-12 (default), 2019-09 and draft-07. Choose the one your validator supports; Ajv, for example, handles all three.