The JSON to GraphQL Schema Generator turns a representative JSON document into a GraphQL Schema Definition Language (SDL) draft. It infers types from your data so you can bootstrap a schema in seconds, then refine the scalar choices by hand. Everything runs in your browser.
How it works
The generator walks the JSON value recursively and builds a type table:
- Scalars —
stringbecomesString,booleanbecomesBoolean, and anumberbecomesIntwhen it is a whole number orFloatotherwise. - Objects — every nested object becomes its own named type, with the type
name derived by PascalCasing the field key (so an
addressfield yields a typeAddress). - Arrays of objects — all elements are merged into one shape. A field is
marked non-null (
!) only when it appears in every element; fields seen in only some elements stay nullable. This is how genuinely optional fields are detected. - Arrays of scalars — become a list of the element scalar, e.g.
[String!].
The top-level object becomes the Root type, which is emitted first, followed
by every named type it references.
Worked example
For this JSON representing an API response with a posts array:
{
"posts": [
{ "id": 1, "title": "First post", "views": 120, "pinned": true },
{ "id": 2, "title": "Second post", "views": 45 }
]
}
The generator produces:
type Root {
posts: [Post]
}
type Post {
id: Int!
title: String!
views: Int!
pinned: Boolean
}
id, title, and views appear in every array element so they are non-null (!). pinned only appears in the first element, so it is nullable — the generator detected it as optional from the data.
What to refine by hand
Because JSON carries no semantic type beyond its primitive shape, the generated SDL is a starting point. Common manual refinements:
| Inferred type | What to change it to | When |
|---|---|---|
Int or String | ID | When the field is an identifier like id, userId |
String | DateTime (custom scalar) | When the value is an ISO 8601 date/time string |
String | URL or Email (custom scalar) | When the field clearly holds a URL or email |
Root | Query or appropriate type | The top-level type in a real GraphQL schema should be named |
Notes
Because JSON carries no semantic type beyond its primitive shape, the output is
a starting point. Replace inferred String identifiers with ID, ISO date
strings with a DateTime scalar, and split large Root objects into proper
query and mutation types as your API design requires.
For richer schemas, feed the generator a real API response with many records in each array — the more diverse the sample, the more accurately it detects which fields are optional.