Loading GraphQL to JSON Schema Converter...

How to Convert GraphQL to JSON Schema - Step by Step Guide

Step 1

Input Your GraphQL Schema

Start with your GraphQL schema definition. Whether you're working with Apollo Server, need to validate schemas, or want to generate JSON Schema docs, you have several options:

•
Paste directly: Copy your GraphQL type definitions and paste into the editor
•
Upload a file: Click "Upload" to select a .graphql or .gql schema file
•
Try the sample: Click "Sample" to load three small types and see the result

Example: GraphQL Schema Input

Here's a sample GraphQL type:

type User {
  id: ID!
  name: String!
  age: Int
  posts: [Post!]!
}

type Post {
  id: ID!
  title: String!
}
Step 2

Automatic Conversion

The converter automatically transforms your GraphQL types to JSON Schema:

•
Type mapping: Int becomes a 32-bit "integer", Float a "number", String and ID a "string", and every named type its own entry under "definitions"
•
Required fields: Non-null fields (!) are listed in "required"; nullable ones also accept null
•
Array handling: GraphQL lists become arrays, and the items follow the same null rules

Example: JSON Schema Output

What the converter produces for the two types in Step 1:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "User": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "age": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": -2147483648,
          "maximum": 2147483647
        },
        "posts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Post"
          }
        }
      },
      "required": [
        "id",
        "name",
        "posts"
      ]
    },
    "Post": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "title"
      ]
    }
  }
}
Step 3

Review and Customize

Verify the generated JSON Schema:

•
Draft-07 output: The schema declares draft-07 and every $ref points at a definition in the same file
•
Descriptions and defaults: GraphQL descriptions become "description", input defaults become "default", written exactly as typed
•
Pick a type: Validate one object by pointing your validator at its definition, for example #/definitions/User
Step 4

Export and Use

Get your JSON Schema ready for use:

•
Copy to clipboard: One-click copy for pasting into your project
•
Download as JSON: Save as .json file for your documentation
•
API validation: Load it into a JSON Schema validator such as Ajv

Frequently Asked Questions

Why turn a GraphQL schema into JSON Schema?

Plenty of tooling speaks JSON Schema and not GraphQL: request validators such as Ajv, form generators, contract tests, mock data tools and documentation sites. Converting the SDL lets those tools check data against the same types your GraphQL server uses, without writing the shapes twice.

How are GraphQL types mapped?

String and ID become "string", Int becomes "integer" limited to the 32-bit range GraphQL allows, Float becomes "number" and Boolean becomes "boolean". Object, interface and input types become objects whose non-null fields are listed in "required". Lists become arrays, enums keep their exact value names, unions become anyOf over $ref links to their member types, and custom scalars get a definition that accepts any value, because GraphQL does not say what JSON a custom scalar uses. In input types an ID may also be an integer, since GraphQL accepts both there.

Why do nullable fields accept null?

Because a GraphQL server really does send null for them. A field typed age: Int can come back as "age": null, so its schema is ["integer", "null"]. Only fields marked with ! are required and refuse null. Inside lists the same rule applies to the items: [String!] rejects a null item, [String] allows one.

What happens to descriptions, deprecations and default values?

Type and field descriptions, including multi-line block strings, are copied into "description". A @deprecated reason is added to the field description. Default values on input fields become "default", written exactly as typed, so 14.50 stays 14.50 and "00501" stays a string. A non-null input field with a default is not required, because GraphQL fills it in for you. Field arguments are not part of the output, since they describe a request, not the returned object.

What if my schema has an error?

Nothing is generated and you see the line and column of the first problem, with the line itself underneath. That covers syntax mistakes, types used but never declared, duplicate names, a type that does not implement its interface, and default values GraphQL would reject, for example an Int default of 8901240544102066246, which does not fit in 32 bits. If you paste a query or JSON by mistake, the page tells you that too.

Can I use the output with Ajv or OpenAPI?

The output declares draft-07 and compiles in Ajv, strict mode included. Validate against one type with {"$ref": "schema.json#/definitions/TypeName"}. OpenAPI 3.1 accepts this JSON Schema as it is; OpenAPI 3.0 uses an older dialect without ["integer", "null"] type lists, so run the result through a JSON Schema to OpenAPI converter first.

Is my schema uploaded anywhere?

No. The conversion runs in your browser with the graphql-js library, and nothing you paste or upload is sent to a server or kept. Reloading the page starts with an empty editor.

Related pages: check a GraphQL schema for errors, turn GraphQL types into TypeScript, convert JSON Schema to OpenAPI and build a JSON Schema from sample JSON.