XML to JSON Schema Generator Online

Paste any XML and generate a JSON Schema Draft 2020-12 document. XML attributes are preserved as @_-prefixed properties (the fast-xml-parser convention) so the schema validates the JSON form of your XML losslessly — all in your browser.

What is an XML to JSON Schema generator?

An XML to JSON Schema generator takes a real XML document and emits a JSON Schema (Draft 2020-12) that describes the JSON form of that XML — typically the JSON you would get from fast-xml-parser or xml2js. The OpenFormatter generator infers types (string, integer, number, boolean, object, array) and preserves XML attributes as @_-prefixed properties so the schema is lossless.

XML differs from JSON in two ways the schema has to honour. First, XML has attributes on elements (<book id="bk101">) — these map to @_id in the JSON tree and therefore to @_id in the schema. Second, XML allows arbitrary repetition of child elements; the generator detects multi-occurrence and emits a JSON Schema array with an inferred items schema.

Sample XML and the JSON Schema it generates

Input XML

<book id="bk101" lang="en">
  <title>JSON Schema in Action</title>
  <year>2022</year>
  <price currency="USD">42.50</price>
</book>

Generated JSON Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "book",
  "type": "object",
  "properties": {
    "book": {
      "type": "object",
      "properties": {
        "@_id":   { "type": "string" },
        "@_lang": { "type": "string" },
        "title":  { "type": "string" },
        "year":   { "type": "integer" },
        "price":  {
          "type": "object",
          "properties": {
            "@_currency": { "type": "string" },
            "#text":      { "type": "number" }
          }
        }
      }
    }
  }
}

Notice @_id and @_lang use the attribute prefix, while title and year appear as plain element names. The nested <price currency="USD">42.50</price> generates an object with @_currency and a #text sibling for the numeric content — exactly the shape fast-xml-parser produces.

How to convert XML to JSON Schema — 4 steps

  1. Paste your XML. A SOAP envelope body, an RSS feed entry, a Spring beans XML — anything well-formed.
  2. Click Convert. The browser parses the XML and generates a JSON Schema Draft 2020-12 covering the full element tree.
  3. Review attribute keys. Confirm that @_-prefixed properties match the attributes you care about; relax required arrays if certain fields are optional.
  4. Drop into your validator. Copy the schema, register it with Ajv 8, Hyperjump, or networknt, and validate JSON payloads downstream of fast-xml-parser.

Draft 2020-12

Output targets the current JSON Schema draft with proper $schema URI — works in Ajv 8, Hyperjump, networknt, and OpenAPI 3.1 schemas/components/schemas.

Attribute Prefix @_

XML attributes become @_-prefixed properties — the fast-xml-parser convention — so the schema validates the JSON form of your XML losslessly.

Client-Side Only

Your XML — including SOAP responses with credentials — is parsed in JavaScript on your machine. Verify in DevTools: zero network requests on Convert.

Common use cases

  • check_circleGenerate a JSON Schema for SOAP envelopes parsed via fast-xml-parser
  • check_circleDocument an RSS or Atom feed in JSON Schema for downstream validators
  • check_circleBuild OpenAPI 3.1 components/schemas from XML samples
  • check_circleValidate Configuration XML translated to JSON in CI pipelines
  • check_circleGenerate schemas for XML scraped from public APIs
  • check_circleDocument SAML or WS-Security payloads as JSON Schema
  • check_circleBootstrap a sitemap.xml or robots.xml schema for tooling
  • check_circleMigrate legacy XSD-driven projects to JSON-Schema-first workflows

Why client-side conversion matters

SOAP responses and enterprise XML often contain customer PII, API tokens, internal endpoint names, and database identifiers. Pasting them into a server-hosted converter is a compliance violation in most regulated industries. OpenFormatter parses the XML and generates the JSON Schema entirely in JavaScript on your device — no upload, no logs, no cookies. Open DevTools → Network and confirm no requests fire when you click Convert.

More XML tooling

Validate, format, or convert XML to other languages — every tool runs locally in your browser.

Frequently Asked Questions

How are XML attributes represented in JSON Schema?

XML attributes are represented as object properties whose keys are prefixed with @_ — the same convention popularised by fast-xml-parser. So <book id="bk101"> becomes a JSON Schema property named "@_id". This avoids name collisions when an attribute shares a name with a child element (e.g. an "id" attribute alongside an <id> sub-element).

Which JSON Schema draft does the output target?

Draft 2020-12 — the current published draft on json-schema.org. The $schema URI is set to https://json-schema.org/draft/2020-12/schema. The schema is forward-compatible with most validators (Ajv, Hyperjump, networknt) running 2020-12 strict mode. Downgrading to draft-07 is a one-line change to the $schema URI.

What about CDATA sections?

CDATA blocks are treated as plain text content — the DOMParser strips the CDATA wrapper and returns the inner text. The inferred property carries type "string" with no special marker. If you need to preserve the CDATA boundary in your final JSON document, post-process the schema to add a custom keyword like "x-cdata: true" on the affected text nodes.

How are repeated elements typed?

Repeated child elements (e.g. multiple <tag> inside <tags>) become a JSON Schema array — { "type": "array", "items": { ... } } — where the items schema is inferred from the first occurrence. If your real data has heterogeneous shapes across instances, broaden items to oneOf or use Spectrum / quicktype to unify them.

Why @_ as the attribute prefix instead of @?

A leading @ on a JSON property is technically valid, but most JSONPath libraries reserve @ for the current-node selector and many serializers strip it as JSON-LD context. The @_ convention from fast-xml-parser is widely interoperable, plays nicely with TypeScript identifiers when you bracket-access them, and survives every JSON validator we tested.

Does the output validate the source XML literally, or the JSON form of it?

It validates the JSON form. The schema describes the JSON tree you would get after parsing the XML with fast-xml-parser (or a similar XML-to-JSON converter using @_ for attributes). To validate raw XML, use an XSD instead — convert XML to XSD with a tool like XmlGrid or Trang, then ingest the XSD into your XML validator.

Is the XML I paste sent to your servers?

No. XML is parsed by the browser DOMParser and the JSON Schema is generated entirely in JavaScript on your machine. Open DevTools → Network and you will see no requests when you click Convert. Safe for SOAP responses and configuration files containing API keys or credentials.

Can I use this schema in OpenAPI?

Almost directly. OpenAPI 3.1 fully aligns with JSON Schema 2020-12, so you can paste the schema body under components/schemas with no changes. For OpenAPI 3.0 (a frozen subset of an older draft), drop $schema, replace tuple validation, and use nullable: true instead of "type": ["string", "null"].

XML to JSON Schema Generator Online — Free