JSON to GraphQL Schema Generator

JSON Input
1
Root Type
GraphQL Schema

Last updated:

Jsonic's JSON to GraphQL Schema Generator converts a JSON object into GraphQL SDL (Schema Definition Language) type definitions instantly in your browser. Fields with non-null values receive the ! non-null marker; fields with null values are left nullable. JSON strings map to String, integers to Int, decimals to Float, booleans to Boolean, and arrays to [Type!]! list types. Nested objects each generate a separate named type defined above the type that references it. A type Query block with a root field is appended automatically so the schema is immediately usable. All processing runs client-side — no data is uploaded.

Mapping JSON scalars to GraphQL types

GraphQL is statically typed, so every JSON value has to land on a concrete scalar. The generator reads the literal value, not just the key: a number with no decimal point becomes Int, a number with a decimal becomes Float, quoted text becomes String, and true/false becomes Boolean. JSON has no date type, so timestamps stay String until you define a custom scalar.

// JSON input
{
  "id": 1,
  "title": "Intro to GraphQL",
  "rating": 4.5,
  "published": true,
  "publishedAt": "2026-06-17T09:00:00Z"
}

// Generated SDL
type Article {
  id: Int!
  title: String!
  rating: Float!
  published: Boolean!
  publishedAt: String!
}

Nested objects become their own types

GraphQL has no inline anonymous object type. Each nested JSON object is therefore lifted into a separate named type (PascalCased from the field name), emitted above the type that references it, and linked by field. A two-level object produces two type declarations.

// JSON input
{
  "title": "Intro to GraphQL",
  "author": {
    "name": "Ada Lovelace",
    "verified": true
  }
}

// Generated SDL — Author is defined first, then referenced
type Author {
  name: String!
  verified: Boolean!
}

type Article {
  title: String!
  author: Author!
}

Arrays map to GraphQL list types

A JSON array becomes a list written in bracket notation. The element type is inferred from the first item: an array of strings is [String!]!, and an array of objects generates a named element type first. The default [Type!]! means the list cannot be null and no element can be null — loosen it to [Type] if either can be.

// JSON input
{
  "title": "Intro to GraphQL",
  "tags": ["graphql", "schema", "sdl"],
  "comments": [
    { "body": "Great post", "likes": 12 }
  ]
}

// Generated SDL
type Comment {
  body: String!
  likes: Int!
}

type Article {
  title: String!
  tags: [String!]!
  comments: [Comment!]!
}

Nullable vs non-null (the ! marker)

A field is rendered non-null (with !) whenever the sample value is present and not null; a JSON null makes the field nullable. Since the tool sees only one sample, treat ! as a starting guess — if a field can be null in production but happened to be filled in your example, drop the !. Non-null is a hard contract: a ! field that resolves to null errors the whole response.

// JSON input — bio is null, deletedAt is null
{
  "name": "Ada Lovelace",
  "bio": null,
  "deletedAt": null
}

// Generated SDL — null fields lose the !
type User {
  name: String!
  bio: String
  deletedAt: String
}

Refining ids and enums by hand

Two things cannot be inferred from a single sample. A numeric id maps to Int! by literal type, but GraphQL convention is the ID scalar, which serializes as a string and stays consistent across REST, databases, and caches. And a field like "status": "ACTIVE" is just a string to the generator — only you know the full value set, so promote it to an enum after generating.

// Generated (literal inference)
type User {
  id: Int!
  status: String!
}

// Refined by hand — ID scalar + enum
enum UserStatus {
  ACTIVE
  INACTIVE
  PENDING
}

type User {
  id: ID!
  status: UserStatus!
}

The root Query type and using the schema

A schema is invalid without a root Query type — it is where every query begins. The generator appends a type Query block returning your top-level type so the SDL loads in Apollo Server, graphql-js, or Pothos without a "Query root type must be provided" error. You still write the resolver yourself.

// Appended automatically
type Query {
  article: Article!
}

// Paste straight into Apollo Server as typeDefs
import { ApolloServer } from '@apollo/server'
const server = new ApolloServer({ typeDefs, resolvers })

For the full workflow — query structure, graphql-request, graphql-codegen, and JSON Schema mapping — read the JSON to GraphQL guide. If you only need plain types for a REST API, use JSON to TypeScript instead.

How to convert JSON to a GraphQL schema

  1. Paste your JSON object into the left panel, or click Example to load a sample.
  2. Optionally change the root type name (default: Root).
  3. Click Generate.
  4. Copy the SDL output from the right panel.
  5. Paste the SDL into your schema.graphql file or as the typeDefs string in Apollo Server.

FAQ

What GraphQL SDL version does this generate?

The tool generates SDL per the June 2018 GraphQL specification. The output is compatible with Apollo Server, graphql-js, Pothos, Strawberry, and any other GraphQL implementation that follows the spec. Non-null fields use the ! syntax, list types use bracket notation, and each object type is declared with the type keyword.

How are JSON types mapped to GraphQL types?

JSON strings map to String, JSON integers (whole numbers) map to Int, JSON decimals map to Float, JSON booleans map to Boolean, JSON null causes the field to be nullable (no ! suffix), JSON arrays map to [Type!]! (a non-null list of non-null elements), and JSON objects each generate a separate named GraphQL type.

How is nullability determined?

Any field whose JSON value is null is treated as nullable and rendered without the ! non-null marker. Every other field — string, number, boolean, array, or nested object — is treated as non-null and rendered with !. If you know a field can sometimes be null in production even if the sample does not show it, remove the ! suffix manually after generating.

How do nested objects work?

Each nested JSON object generates a separate named GraphQL type. The type name is derived from the field name converted to PascalCase. Nested types are emitted before the type that references them, so the SDL is ordered correctly. For example, a field "address": { "city": "Paris" } produces an Address type with a city: String! field, and the parent type references it as address: Address!.

Can I use this with Apollo Server?

Yes. Copy the generated SDL and paste it directly as the typeDefs string in Apollo Server: const server = new ApolloServer({ typeDefs, resolvers }). Alternatively, save the SDL to a schema.graphql file and load it with gql or a file loader. The generated schema includes a type Query block so Apollo Server starts without requiring you to add one manually.

What about unions and interfaces?

This tool generates simple object types from the JSON structure it observes. GraphQL unions (used when a field can return different types) and interfaces (shared field sets across types) cannot be inferred from a JSON sample alone and require manual schema design. After generating the base types, you can introduce union and interface declarations by hand to model polymorphic relationships in your API.