Loading GraphQL to JSON Converter...

How to Convert GraphQL to JSON - Step by Step Guide

Step 1

Input Your GraphQL Schema or Query

Start with your GraphQL schema or query. Whether you're working with Apollo Server, need to analyze schema structure, or want to format GraphQL first, you have several options:

•
Paste directly: Copy your GraphQL schema or query and paste into the editor
•
Upload a file: Click "Upload" to select a .graphql or .gql file
•
Try the sample: Click "Sample" to see conversion in action

Example: GraphQL Schema Input

Here's a sample GraphQL schema:

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

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

Automatic Conversion to JSON

The converter automatically transforms your GraphQL to structured JSON:

•
Schemas: Every type you define becomes an entry with its fields, arguments, default values, descriptions and directives
•
Queries: Operations, variables, aliases, arguments, directives and fragments are written out as JSON format
•
Exact values: Numbers and strings keep the spelling you typed, and mistakes are reported with their line and column

Example: JSON Output

The start of the JSON for the schema above (Post and the rest of the fields follow the same pattern):

{
  "schema": {},
  "types": [
    {
      "name": "User",
      "kind": "ObjectTypeDefinition",
      "fields": [
        { "name": "id", "type": "ID!" }, …
      ]
    }, …
  ]
}
Step 3

Review JSON Structure

Examine the generated JSON representation:

•
Valid JSON: Any JSON parser can read the output
•
Nothing rounded: A default like 8901240544102066246 is written exactly as in your GraphQL
•
Ready for scripts: Diff schema versions, count fields or feed a documentation generator
Step 4

Export and Use

Save your JSON output for various uses:

•
Copy to clipboard: One-click copy for pasting into your application
•
Download as JSON: Saved as graphql-schema.json or graphql-query.json
•
Uses the current input: Copy and Download convert what is in the editor right now

Frequently Asked Questions

Why convert GraphQL to JSON?

JSON is easier to work with in scripts. Once a schema is a list of types and fields, you can diff two versions, count fields, feed it to a documentation generator or check naming rules with a few lines of code, without writing a GraphQL parser yourself.

What does the JSON for a schema contain?

A "schema" object naming the query, mutation and subscription types, any custom directive definitions, and a "types" list. Each type has its name and kind, plus its description, interfaces and applied directives where it has them. Object, interface and input types list their fields with type, description, arguments, default values and deprecation reason; enums list their values, unions list their member types. Built-in scalars such as String, Int and ID are left out, since every schema has them.

And for a query?

You get a "Document" with one entry per operation or fragment. An operation shows whether it is a query, mutation or subscription, its name, its variables with their types and defaults, and its fields. Each field keeps its alias, arguments, directives such as @include, and nested fields. Fragment spreads and inline fragments are listed by name and type condition. If you paste a schema and a query together, the query goes under "operations" next to the schema.

Are numbers and strings kept exactly?

Yes. graphql-js keeps every number as the text you typed, and this page writes that text straight into the JSON, so a default of 8901240544102066246, 14.50 or 1e3 comes out unchanged instead of being rounded by JavaScript. Strings are written as graphql-js reads them, so "00501" stays a string and block strings lose only their common indentation. Variables appear as "$name" and enum values as their name in quotes.

Is this the same as an introspection result?

No. An introspection result comes from running the introspection query against a live server and has its own fixed layout (__schema, ofType chains and so on). This page reads the schema text instead, uses a simpler layout and adds things introspection leaves out, such as applied directives. Tools that expect an introspection result will not read it directly.

What happens when my GraphQL has an error?

You get the line and column of the problem and the message from graphql-js, for example a missing brace, a field type that is never defined, a fragment that is used but not written, or an argument given twice. Nothing is converted until it is fixed. If you paste JSON by mistake, the page tells you so.

Is my schema uploaded anywhere?

No. The conversion runs in your browser, so the GraphQL is not sent to our server, and nothing is kept: reloading the page starts with an empty editor.

Related pages: check a schema for errors, format a query, generate TypeScript types, or go the other way with JSON to GraphQL.