Loading GraphQL to JSON Converter...
How to Convert GraphQL to JSON - Step by Step Guide
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:
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!
}Automatic Conversion to JSON
The converter automatically transforms your GraphQL to structured JSON:
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!" }, … ] }, … ] }
Review JSON Structure
Examine the generated JSON representation:
Export and Use
Save your JSON output for various uses:
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.
Related Tools
GraphQL Query Formatter
Format and beautify GraphQL queries and schemas with syntax highlighting
GraphQL Schema Validator
Validate GraphQL schemas with syntax and structure checking
GraphQL Fixer
Fix broken GraphQL queries and schemas automatically, repair syntax errors and malformed types
GraphQL to TypeScript
Generate TypeScript types from GraphQL schemas and queries
GraphQL Minifier
Compress and optimize GraphQL queries for production
GraphQL to JSON Schema
Convert GraphQL schemas to JSON Schema format