Developer Tools

JSON to GraphQL

Paste JSON and get a GraphQL schema in SDL that describes it. Objects become types named after their keys, required fields are marked non-null with !, lists get the right item types, id fields can become ID, and you can add matching input types and a Query type to start a server. The generated schema is checked with graphql-js, the reference implementation, before it is shown.

  • Runs in your browser
  • No sign-up
  • Free to use

How to use JSON to GraphQL

  1. Paste a JSON sample.
  2. Set the root type name.
  3. Choose non-null, ID, input and Query options.
  4. Copy the schema or download schema.graphql.

JSON to GraphQL features

Object types

One GraphQL type per JSON object, reused for identical shapes.

Nullability

Non-null ! only for fields present and non-null in every sample.

Scalars

String, Int (32-bit), Float, Boolean, ID and a JSON scalar for mixed values.

Input types

Optional XxxInput types for mutations.

Query type

A starter Query with a list or by-id field.

Validated

Built with graphql-js to catch errors.

When to use JSON to GraphQL

  • Wrapping an existing REST API in a GraphQL server.
  • Sketching a schema from example data in a design discussion.
  • Creating types for a GraphQL mock server.
  • Teaching how JSON structures map to GraphQL types.

JSON to GraphQL FAQ

How is nullability decided?

A field gets ! when it is present and non-null in every object of the sample. Fields that are missing or null anywhere stay nullable, which is GraphQL’s default.

Why Float for some whole numbers?

GraphQL’s Int is a signed 32-bit integer. Larger whole numbers are typed Float; for identifiers, ID is usually better.

What is the JSON scalar?

A custom scalar for values whose type varies. GraphQL has no built-in “any” type, so the server needs a scalar implementation such as graphql-type-json.

Why were some field names changed?

GraphQL names may only contain letters, digits and underscores and cannot start with a digit or “__”. Keys like "is-active" become isActive; your resolvers must map them.

Are the input types complete?

They mirror the object types, which is a good start for create and update mutations. Remove fields such as id or timestamps that clients should not send.

Is my JSON uploaded?

No. The schema is generated and validated in your browser.

From JSON data to a GraphQL schema

A GraphQL API is defined by its schema: a set of types with typed fields, written in the Schema Definition Language. When the data already exists as JSON, for instance from a REST API you want to wrap or from a database export, the structure of that JSON is most of the schema. This tool derives it automatically.

Each JSON object becomes an object type. Fields map to GraphQL’s built-in scalars: strings to String, whole numbers to Int when they fit in 32 bits and to Float otherwise, decimals to Float and booleans to Boolean. Fields named id can become the ID scalar, which GraphQL clients treat as an opaque identifier and use for caching.

Nullability is explicit in GraphQL and works the opposite way from many languages: fields are nullable unless marked with !. The generator adds ! only where the sample shows a value in every object, and lists get both an item-level and a list-level !, as in [Order!]!, when appropriate. Be conservative: removing ! later is a breaking change for clients only in one direction.

Input types are a separate kind of type used for arguments, typically for mutations. They cannot contain object types, so the generator creates parallel XxxInput types that reference each other. A small Query type with a list or lookup field gives a schema that a server such as Apollo Server or GraphQL Yoga can start with immediately.

Before the schema is shown, it is built with graphql-js, the reference implementation of the GraphQL specification, so syntax and type errors are caught early. Use the GraphQL Formatter to adjust the layout and the GraphQL Query Validator to test queries against the generated schema.

Other useful tools