XML to JSON Schema
Infer a JSON Schema from XML sample data with automatic type detection, array inference, and attribute handling.
About This Tool
The XML to JSON Schema converter is a free browser-based tool that analyzes XML sample data and infers a corresponding JSON Schema definition. Instead of manually writing a JSON Schema from scratch, you can paste real-world XML and let the tool derive the structure, types, and constraints automatically.
The converter parses your XML and examines every element,
attribute, and text node. Elements are mapped to
object types with their child elements becoming
properties. Repeated sibling elements of the same tag name
are detected and converted to array types. XML
attributes can be represented with a configurable prefix
(@attr or _attr), and text content within mixed
elements gets its own property key (#text or _text).
Type inference goes beyond simple string mapping. The tool examines text content and attribute values to determine whether they represent strings, numbers, integers, or booleans. When the same element contains different types across occurrences, the schema uses a type union. You can also enable required field detection, which marks properties that appear in every occurrence of their parent element as required.
You can choose between JSON Schema Draft 7 and the newer 2020-12 specification. The output includes a tree view for quick visual inspection and a full JSON view for copying into your projects. Built-in presets for common XML formats like RSS feeds, SVG documents, and Maven POM files let you explore the tool immediately.
All processing happens entirely in your browser. Your XML data never leaves your machine — there are no server round-trips, no logging, and no third-party services involved. This makes it safe to use with production XML data and sensitive configurations.
How to Use
- Paste your XML sample data into the XML Input panel on the left.
- The JSON Schema output updates automatically in the right panel as you type.
- Select the Schema version (Draft 7 or 2020-12) from the dropdown.
- Choose the Attr prefix (
@or_) to control how XML attributes appear in the schema. - Choose the Text key (
#textor_text) to control the property name for mixed text content. - Toggle required to automatically detect and mark required fields based on element frequency.
- Switch between JSON and Tree views using the toggle above the output panel. Click Copy or press Ctrl+Shift+C to copy the generated schema to your clipboard.
Popular XML to JSON Schema Examples
FAQ
How are XML elements mapped to JSON Schema types?
Simple elements with only text content are mapped to scalar types (string, number, integer, or boolean) based on their content. Elements with child elements or attributes become object types with properties. Repeated sibling elements of the same tag name are detected as arrays.
How does attribute handling work?
XML attributes are converted to properties in the JSON Schema with a configurable prefix. By default, the @ prefix is used (e.g., @id, @class), but you can switch to _ prefix (_id, _class) for environments where @ is not supported in property names. Attribute values are type-inferred just like text content.
How are arrays detected from XML?
When multiple sibling elements share the same tag name within a parent element, the tool infers that they form an array. The array detection threshold setting controls how this works. The schemas of all occurrences are merged to produce a unified item schema for the array.
Which JSON Schema versions are supported?
The tool supports JSON Schema Draft 7 (the most widely used version) and the newer 2020-12 specification. The $schema URL in the output changes accordingly, and the generated schema follows the conventions of the selected version.
How does type inference work for text content?
The tool examines the actual text values in your XML to determine types. Values like 'true' or 'false' become boolean, whole numbers become integer, decimal numbers become number, and everything else becomes string. If the same element contains different types across different occurrences, the schema uses a type union (e.g., ["string", "integer"]).
Is my data safe?
Yes. All parsing and schema generation runs entirely in your browser using JavaScript and the built-in DOMParser API. No data is sent to any server. You can verify this by checking the Network tab in your browser's developer tools while using the tool.
Can I use this with namespaced XML?
Yes. The tool processes XML with namespaces. Namespace prefixes (like soap:Envelope) are preserved as-is in the schema property names. The generated schema reflects the exact tag names as they appear in your XML, including any namespace prefixes.
Related Tools
JSON Schema Generator
Generate JSON Schema from sample JSON data with type inference, required fields, and nested object support.
JSON ↔ XML Converter
Convert between JSON and XML formats instantly with customizable root element and attribute handling.
XML Formatter
Format, validate, and minify XML with customizable indentation and syntax error highlighting.
JSON to YAML Schema
Generate YAML Schema from JSON data automatically. Validate CI/CD configs, Kubernetes manifests, and more.
JSON Formatter
Format, validate, and beautify JSON with syntax highlighting and tree view.