JSON to GraphQL Schema Generator

Generate a GraphQL SDL schema from a sample JSON object

Free in-browser JSON to GraphQL schema generator. Paste a sample JSON object and infer GraphQL SDL types — JS types map to GraphQL scalars, nested objects become named types, and arrays of objects merge keys so optional fields stay nullable. Runs locally, nothing uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How are JSON types mapped to GraphQL scalars?

Strings map to String, booleans to Boolean, and numbers to Int or Float depending on whether the value is a whole number. Nested objects become their own named GraphQL type, and arrays become list types based on their element type.

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:

  • Scalarsstring becomes String, boolean becomes Boolean, and a number becomes Int when it is a whole number or Float otherwise.
  • Objects — every nested object becomes its own named type, with the type name derived by PascalCasing the field key (so an address field yields a type Address).
  • 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 typeWhat to change it toWhen
Int or StringIDWhen the field is an identifier like id, userId
StringDateTime (custom scalar)When the value is an ISO 8601 date/time string
StringURL or Email (custom scalar)When the field clearly holds a URL or email
RootQuery or appropriate typeThe 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.