JSONToonPro
GraphQL schema generator

JSON to GraphQL Schema Generator

Convert JSON objects and API responses into GraphQL type definitions instantly. Nested objects become separate types, id fields map to the ID scalar, and you can add a Query type with one click, all client-side with no upload needed.

100% client sideNested typesDownload .graphql
Root type
3 types
Input/ JSON
378 chars21 lines
Output/ GraphQL Schema
293 chars23 lines

Schema Definition Language Basics

GraphQL schemas are written in SDL, a small declarative language with very few concepts. A type declares a named object with a set of fields. Each field has a name and a type. The leaf types are scalars, which hold actual values rather than further structure.

Generating SDL from a JSON sample maps cleanly: each object becomes a type, each key becomes a field, each nested object becomes another type, and each array becomes a list. The generator's job is choosing scalars and inventing type names.

Side by Side Example

A blog post payload and the schema it produces.

JSON input

{
"id": "post_44",
"title": "Working with SDL",
"word_count": 1840,
"rating": 4.6,
"published": true,
"author": {
"id": "usr_7",
"name": "Rosa Klein"
},
"comments": [
{ "id": "c1", "body": "Useful",
"score": 3 },
{ "id": "c2", "body": "Thanks",
"score": 8 }
]
}

GraphQL SDL

type Author {
id: ID!
name: String!
}
 
type Comment {
id: ID!
body: String!
score: Int!
}
 
type Post {
id: ID!
title: String!
wordCount: Int!
rating: Float!
published: Boolean!
author: Author!
comments: [Comment!]!
}

Scalar Mapping

JSON valueGraphQL scalarNotes
TextStringUTF-8, the default for anything textual
Whole numberIntSigned 32 bit, range roughly plus or minus 2.1 billion
Decimal numberFloatDouble precision, do not use for currency
true or falseBooleanDirect mapping
A key named id or ending in _idIDSerialised as a string, signals an identifier
Large integer such as a millisecond timestampFloat or a custom scalarExceeds Int range, a BigInt scalar is cleaner
ISO date stringString or a custom DateTime scalarGraphQL has no built-in date type
Null onlyString, best guessNothing to infer from
ObjectA new typeNamed from the key, PascalCased
ArrayA list typeElement type inferred from the first element

Int overflowing is a real production issue rather than a theoretical one. A Unix timestamp in milliseconds is about 1.7 trillion, comfortably outside the 32 bit range, and a server will raise a serialisation error when it tries to return it as an Int. Define a custom scalar for large numbers, dates, and money.

Nullability Is Inverted

This is the concept that trips up everyone arriving from another language. In GraphQL, every field is nullable by default. The exclamation mark marks a field as non-null. It is the opposite of TypeScript, where a field is required unless you mark it optional.

The reason is error handling. If a resolver fails, GraphQL returns null for that field and reports the error alongside the partial data. Marking a field non-null removes that option: the error must propagate upward to the nearest nullable parent, and if there is none, the entire response data becomes null. Non-null is therefore a statement about failure behaviour, not just about data.

Lists have four combinations

Written asThe list itselfEach itemReads as
[Comment]May be nullMay be nullLoosest, allows null holes in the list
[Comment!]May be nullNever nullEither no list, or a clean list
[Comment]!Never nullMay be nullAlways a list, possibly with null entries
[Comment!]!Never nullNever nullAlways a list, always clean, usually what you want

For a collection, [Comment!]! is nearly always the right choice, because an empty list already expresses the absence of results and a null list adds a second empty case for clients to handle.

Naming Conventions

  • Types are PascalCase and singular: Post, Comment, AuthorProfile.
  • Fields are camelCase, so a JSON key of word_count becomes wordCount.
  • Enum types are PascalCase and their values are SCREAMING_SNAKE_CASE.
  • Input types used as mutation arguments are suffixed with Input, as in CreatePostInput.
  • Boolean fields read naturally as questions: isPublished or hasComments rather than published_flag.
  • Avoid the Get prefix on query fields. The field is post, not getPost, because the operation type already says it is a read.

A Generated Schema Is a Starting Point

What comes out of a JSON sample is a set of object types. A working GraphQL API needs considerably more, and none of it can be inferred from data.

  1. A Query type defining the entry points, including arguments for filtering and pagination.
  2. A Mutation type for writes, with input types rather than long argument lists.
  3. Resolvers, since the schema describes shape and nothing about where data comes from.
  4. Deliberate nullability. The generator marks fields non-null because the sample had values, which is not the same as those fields being guaranteed.
  5. Enums for fields with a fixed set of values. A status field typed String tells a client nothing, while an enum makes the possibilities discoverable in any GraphQL explorer.
  6. Interfaces and unions where several types share a shape or a field can return one of several types.
  7. Pagination, usually the connection pattern with edges, nodes, and a cursor, rather than a bare list.
  8. Descriptions, written in triple quoted strings. They surface as documentation in every GraphQL client and cost almost nothing to add.

Two more things the generator cannot see: a field that appeared once in your sample may be repeatable in reality and should be a list, and circular references between types are normal in GraphQL but impossible to spot in a single flat payload.

Schema definitions pair naturally with other type artefacts. Visit the full converter collection for JSON to TypeScript to type the client side of the same payload, JSON Schema for runtime request validation, and JSON to SQL for the tables your resolvers will read from.

How to generate a GraphQL schema from JSON

Three steps
01

Paste or upload JSON

Add a JSON object or API response to the input panel. Use the sample button to load a realistic user and posts example.

02

Configure schema options

Toggle non-nullable fields, the ID scalar for id fields, an optional Query type, and rename the root type.

03

Copy or download schema

GraphQL types update live as you type. Copy the output or download a ready-to-use .graphql file.

Built for GraphQL developers

Bootstrap your GraphQL schema from existing REST API responses or JSON data models in seconds, then extend with resolvers and custom scalars.

100% client side

Your JSON never leaves the browser. No upload, no server, no logs.

Live generation

GraphQL types update instantly as you type or change options.

Nested types

Nested objects each get their own named type in PascalCase with all fields inferred.

Non-nullable control

Toggle the ! suffix on all fields to match your API's nullability requirements.

ID scalar

Fields named 'id' or ending in 'Id' are automatically mapped to the GraphQL ID scalar.

Download .graphql

Export a complete GraphQL schema file ready to use with Apollo or any GraphQL server.

Frequently asked questions

7 answers
Paste your JSON object or array into the input panel. GraphQL type definitions are generated instantly. Nested objects become separate named types and arrays of objects produce typed list fields.

GraphQL Schema Generator from JSON Data

This tool infers GraphQL scalar types from JSON values: strings become String, integers become Int, floats become Float, and booleans become Boolean. Fields named id or ending in Id are mapped to the ID scalar. Nested objects generate separate named types in PascalCase. Arrays of objects produce list fields. All types are output in dependency order so nested types appear before the parent types that reference them. Download the result as a .graphql file to use directly with Apollo Server, GraphQL Yoga, or any schema-first GraphQL framework.

More JSON Tools