JSON to GraphQL
Infer GraphQL schema definition language from a JSON payload. Fields present in every record get the non-null ! marker, optional and nullable ones stay nullable, nested objects become their own types, and you can optionally emit matching input types and a starter Query.
How to generate a GraphQL schema from JSON
- Paste a JSON sample — ideally an array of several records, so optional fields are detected.
- Set the Root type name. Nested objects are named after the key that holds them, singularised for arrays.
- Pick the integer scalar. GraphQL's built-in
Intis signed 32-bit — if your IDs exceed 2,147,483,647 you need a custom scalar or aString. - Tick input types if clients will send this shape back in a mutation; GraphQL requires separate input types for that.
- Copy the code, or download it as a file.
What the non-null markers mean
A field is marked ! only when it was present and non-null in every record you pasted. That
makes the sample size significant: two records where one omits email correctly produce a
nullable email, whereas a single record marks it required and your schema will lie to
clients. Err towards nullable — loosening a field later is a breaking change for clients that relied on
non-null.
Field names and keys
By default field names match the JSON keys exactly, so a resolver can return the parsed object untouched. GraphQL convention is camelCase, so tick camelCase field names if you would rather follow that — you will then need resolvers, or a field-name transform, to map back to the underlying keys.
Getting good types out of a sample
Type inference from a sample is only as good as the sample. Three habits make the output far more useful:
- Paste an array, not one record. When you pass several records, a key missing from any of them is marked optional and a field that is sometimes a number and sometimes a float widens to a float. One record makes everything look required.
- Include the awkward cases. A record with a null, an empty array, and a missing optional key teaches the generator more than ten identical happy-path records.
- Check unions by hand. A field that holds different shapes in different records falls back to the language's "any" type. That is a signal your data has a variant the generator cannot express — model it explicitly.
Privacy
Nothing is uploaded. Inference and code generation run in this tab. No server sees the payload you paste — which matters, because real API responses tend to contain real user data.
FAQ
Can it infer enums?
No. A repeated string value might be an enum or might be a coincidence in your sample, and guessing wrong bakes a breaking change into your schema. Promote them to enums by hand once you know the full value set.
What is the JSON scalar in my output?
A placeholder for values whose type could not be inferred — a null-only field, or one whose type varies. GraphQL has no built-in JSON scalar, so either define one (graphql-scalars provides it) or replace the field with a concrete type.
Why are lists [String!]! and not [String]?
Because in the sample the list was present and no element was null. [String!]! means "a list that always exists, containing no nulls" — the strongest contract the data supports. Loosen it if your API can return nulls inside the list.