JSON to GraphQL Schema Generator
Paste JSON, get GraphQL type definitions — nested types, arrays, nullable fields, input types
Options
363 characters
3 types generated · 318 characters
You’re migrating a REST API to GraphQL. The REST endpoint returns a 40-field nested JSON response with users, posts, and comments. You need a GraphQL schema with type User, type Post, type Comment, proper scalar types, and nullable fields — and you need it now, not after an hour of writing SDL by hand.
Why This Generator (Not json-to-go or json-to-typescript)
PureDevTools has JSON-to-code generators for Go, TypeScript, Python, Rust, and SQL. This tool generates GraphQL SDL type definitions — type, input, scalar inference (String, Int, Float, Boolean, ID), and nullable field detection. Use the other generators for language-specific types; use this one for your .graphql schema file.
What Is a JSON to GraphQL Schema Generator?
When building a GraphQL API, you need to define type definitions in the Schema Definition Language (SDL). Writing these types by hand from an existing JSON payload — an API response, a database record, or a configuration object — is repetitive and error-prone, especially for large or deeply nested structures.
A JSON to GraphQL schema generator reads your JSON and automatically produces correct GraphQL type definitions, handling:
- Nested objects (each becomes its own named GraphQL type)
- Arrays of objects (merged into a single type with optional/nullable fields for missing keys)
- Scalar type inference:
String,Int,Float,Boolean - Non-null enforcement (
!) or nullable mode based on your preference - Optional
id: ID!field injection for types that lack one - Input type generation for mutation arguments
This tool runs entirely in your browser — your JSON data never leaves your device.
How to Use This Tool
- Paste your JSON in the JSON Input textarea (or click Load sample to try an example)
- Configure options: root type name, nullable fields, add ID field, generate input types
- The GraphQL schema (SDL) updates instantly in the GraphQL Schema panel
- Click Copy to copy to clipboard, or Download .graphql to save as a file
Understanding GraphQL Scalars
GraphQL has five built-in scalar types. The generator maps JSON values as follows:
| JSON value | GraphQL scalar |
|---|---|
"hello" (string) | String |
42 (integer) | Int |
3.14 (float) | Float |
true / false (boolean) | Boolean |
null | field is nullable (no !) |
If an array contains both integers and floats, the element type is widened to Float. If an array contains incompatible scalar types (e.g., strings and numbers), String is used as the fallback.
Non-Null vs Nullable Fields
In GraphQL SDL, fields are nullable by default. Adding ! after a type makes the field non-null — the server guarantees a value will always be present:
type User {
id: ID! # non-null: always present
name: String! # non-null: always present
bio: String # nullable: may be null
}
This tool defaults to non-null (!) for all fields inferred from concrete JSON values. Fields whose source JSON value is null are always nullable. Enable nullable fields to omit ! from all generated fields.
Naming Convention for Generated Types
Type names are derived from the JSON property path using PascalCase:
- Root object → the name you specify (default:
Root) - Nested property
address→RootAddress - Nested property
cityinsideaddress→RootAddressCity(if it were an object) - Array property
posts→ element typeRootPostsItem, field type[RootPostsItem]
Input JSON:
{
"user": {
"id": 1,
"address": { "city": "New York" }
}
}
Generated GraphQL:
type Root {
user: RootUser!
}
type RootUser {
id: Int!
address: RootUserAddress!
}
type RootUserAddress {
city: String!
}
Options Explained
Root Type Name
The name given to the top-level GraphQL type. Defaults to Root. If your JSON represents a User object, set the root type name to User for cleaner output:
type User {
id: Int!
name: String!
}
Nullable Fields
By default, inferred fields are marked non-null (!). Enable this option to make all fields nullable (remove !):
type Root {
name: String # nullable — may return null
age: Int # nullable
}
Use nullable fields when your JSON represents partial data or when your GraphQL server may return null for some fields.
Add ID Field
Injects an id: ID! field at the top of every generated type that does not already contain an id field:
type Root {
id: ID!
name: String!
email: String!
}
This is useful when you know your entities will have a globally unique identifier field for GraphQL caching (used by Apollo Client and Relay).
Generate Input Types
Creates a parallel input type for every object type. Input types are used in GraphQL mutations as argument types:
type User {
name: String!
email: String!
}
input UserInput {
name: String
email: String
}
Input type fields are always nullable (no !) — this allows partial updates where clients only send the fields they want to change.
Handling Arrays of Objects
When a JSON array contains objects, all objects are merged into a single GraphQL type. Fields absent from some objects become nullable:
Input JSON:
{
"posts": [
{ "id": 1, "title": "Hello World", "published": true },
{ "id": 2, "title": "GraphQL Tips" }
]
}
Generated GraphQL:
type Root {
posts: [RootPostsItem]!
}
type RootPostsItem {
id: Int!
title: String!
published: Boolean
}
The published field is nullable because it is absent from the second object.
Handling null Values
JSON null maps to a nullable field (no !) regardless of the nullable fields option:
{ "deletedAt": null }
Generates:
type Root {
deletedAt: String
}
Common Use Cases
API Response Typing
Paste the raw JSON from an API response and generate the corresponding GraphQL types for your schema. This is useful when:
- Adding a new REST endpoint to a GraphQL wrapper/gateway
- Creating types for a database resolver
- Documenting an existing service with a GraphQL facade
Code-First to SDL Migration
If you have TypeScript objects representing your data model, serialize a sample to JSON and generate the corresponding GraphQL SDL types.
GraphQL Schema Bootstrapping
When starting a new GraphQL API, use sample data to quickly scaffold your initial type definitions. Edit and extend the generated output in your schema file.
Relay and Apollo Client Setup
When working with Relay or Apollo Client, every type should have an id: ID! field. Enable the Add ID field option to automatically inject this into all generated types.
After Generating: Refining Your Schema
The auto-generated types are a starting point. Consider:
-
Add custom scalars for dates, email addresses, URLs:
scalar DateTime type Post { createdAt: DateTime! } -
Replace String with enums for finite value sets:
enum Status { ACTIVE INACTIVE PENDING } type User { status: Status! } -
Add query and mutation types to complete a runnable schema:
type Query { user(id: ID!): User users: [User!]! } type Mutation { createUser(input: UserInput!): User! } -
Add descriptions using triple-quote syntax:
""" Represents a registered user in the system. """ type User { "The user's unique identifier" id: ID! } -
Deduplicate common types — if two generated types are structurally identical (e.g.,
UserAddressItemandOrderAddressItem), extract them into a shared type.
FAQ
What GraphQL field names are valid?
GraphQL field names must match [_A-Za-z][_0-9A-Za-z]*. JSON keys that contain hyphens (content-type), spaces, or start with digits are skipped. Rename the keys in your JSON before pasting, or manually add these fields to the generated schema.
Can I use this for GraphQL subscriptions?
The generator produces type definitions, not full schema files. Add subscription { } type and resolver logic manually after generating the data types.
What about Union types?
GraphQL Union types are not automatically generated. If your JSON field can be one of several object shapes, manually define union SearchResult = User | Post | Comment in your schema.
Does this support GraphQL interfaces?
No. The generator produces concrete types only. If you want to extract common fields into a GraphQL interface (e.g., interface Node { id: ID! }), do so manually after generating.
Can I generate a full executable schema?
This tool generates SDL type definitions only — not Query, Mutation, Subscription root types, resolvers, or directives. Add those manually or with a code-generation tool like graphql-codegen.
What happens with circular references in JSON?
Standard JSON.parse cannot represent circular references, so this situation cannot arise from valid JSON input.