DevTools Logo

JSON to GraphQL SDL Converter

JSON to GraphQL SDL Converter

Infer types, nullability, IDs and enums from a JSON sample.

Runs in your browser
Try an example

JSON sample

20 lines · 274 chars

Inferred SDL

2 types · 6 fields · 0 enums
type Address {
  city: String!
  zip: String!
}

type Root {
  id: ID!
  name: String!
  email: String
  address: Address!
}

type Query {
  root: [Root!]!
}

Details

Paste an object or array of objects and get a GraphQL schema definition language starting point. The inferencer counts field presence and null values across every sampled object, maps scalars to Int, Float, Boolean and String, applies an ID heuristic to id-like keys, suggests enums for repeated short string values, and turns nested objects into named types with PascalCase names. Heuristics are toggleable because inferred schemas always need human review.

More examples

Users with addresses

[{"id":1,"name":"Ada","address":{"city":"London"}}]

Produces type Root with an address field and a separate type Address.

Nullability

[{"email":"a@b.test"},{"email":null}]

A field that is null or absent in any sampled object becomes nullable.

Enum candidate

Six rows alternating between active and pending status

Emits an enum type with uppercase members and lists the suggestion.

Examples

Users

Input
[{id:1,name:'Ada',address:{city:'London'}},{id:2,name:'Grace'}]
Output
type Root { id: ID! name: String! address: Address }
type Address { city: String! }

The absent address in the second row makes the field nullable.

Enum candidate

Input
Six rows with status active or pending
Output
enum StatusEnum { ACTIVE PENDING }

Repeated short strings with enough occurrences become an enum suggestion.

Mixed types

Input
[{value:1},{value:'one'}]
Output
value: String

Mixed scalar types fall back to String with a warning.

About this tool

JSON to GraphQL SDL Converter infers a schema definition from a JSON sample. Nested objects become named types, arrays become lists, and every field's nullability is decided by a presence census across all sampled objects.

Scalar mapping follows GraphQL's built-ins: integers become Int, fractional numbers Float, booleans Boolean and everything else String. An ID heuristic recognises id and *Id keys whose values look like identifiers, and an enum heuristic suggests enum types for short repeated strings. Both heuristics are toggleable.

The output is a starting point, not a finished schema. The tool reports warnings for mixed types and sampled arrays and never sends your JSON anywhere; all inference runs in the browser.

What this tool does not do

  • Inference is heuristic; the generated SDL always needs human review.
  • Custom scalars, interfaces, unions, directives and resolvers are not generated.
  • Sampling stops at 1000 array elements.
  • Date and time strings remain String; no custom DateTime scalar detection.
  • Nested arrays of arrays are simplified rather than fully modelled.

How to use this tool

  1. Paste a sample

    Provide an object or an array of objects, ideally with enough rows to expose nullable fields.

  2. Set the root name and options

    Choose the root type name and toggle enum, ID or nullable-all inference.

  3. Review the SDL

    Read the type count, field census and warnings; rename types to match your domain.

  4. Copy the schema

    Copy or download the .graphql file and continue with resolvers and directives.

Use cases

GraphQL bootstrapping

Start a schema from an existing REST response instead of writing types by hand.

Prototyping

Mock a schema shape for fixtures and front-end development.

Reverse engineering

Recover a likely schema from exported sample data.

Inference rules

ObservationSDL
Integer valueInt
Fractional valueFloat
Boolean valueBoolean
id or *Id key with identifier-like valuesID
2–5 repeated short stringssuggested enum type
Field null or absent in any samplenullable field
Nested objectseparate named type

Only the first 1000 objects in a large array are sampled; the tool warns when this happens.

Common mistakes

Mistake:Trusting inferred nullability from a tiny sample.

Fix:Use enough objects to cover optional fields, then review nullable markers manually.

Mistake:Assuming every id-like string is an ID scalar.

Fix:Turn ID detection off for descriptive strings; the heuristic checks length and shape.

Mistake:Accepting enum suggestions without review.

Fix:Enums are suggestions; real domains may add values later.

Mistake:Expecting resolvers or directives.

Fix:This tool emits SDL types only, not server code.

Mistake:Feeding an array of scalars.

Fix:Provide objects or an array of objects so there are fields to infer.

Frequently asked questions

How is nullability inferred?

The converter runs a presence census over every sampled object. A field is marked non-null only when it is present and non-null in every sample that could contain it; a missing or null value in one row makes the field nullable. Small samples are a common source of overly strict schemas, so the tool warns when only a handful of objects were seen.

How are enums detected?

Short string values that repeat across the sample are collected per field. When a field has a small set of distinct values with enough occurrences, the tool suggests an enum type using normalized, GraphQL-safe member names. Enum detection is a suggestion you can disable; values added later in a real API will not be predicted.

Why did my nested object become a separate type?

GraphQL fields cannot contain inline object shapes. Each nested object is promoted to a named type derived from the field name, and the parent field references that type. Deeply nested structures therefore produce several types, which you can rename to match your domain before using the SDL.

Can it handle arrays of mixed shapes?

Yes. Fields are unioned across all array elements, and a field absent from some elements becomes nullable. When the same field carries incompatible scalar types the converter falls back to String and emits a warning rather than inventing a custom scalar. Only the first 1000 elements are sampled from very large arrays.

Are names and scalars customizable?

The root type name, an optional prefix and suffix for generated types, and the ID/enum/nullability heuristics are configurable. Built-in scalars are used for numbers, booleans and strings; dates and other domain-specific values remain String because the tool does not invent custom scalars.

Does the generated SDL include resolvers or directives?

No. The output is schema definition language only: types, fields and suggested enums. Resolvers, query and mutation roots, directives, interfaces and unions are deliberately out of scope and should be added by hand.

Is my JSON uploaded anywhere?

No. Parsing, the field census and SDL generation all run in your browser tab. Nothing is transmitted, and the sample is not stored after you leave the page.

References & standards