JSON to GraphQL schema converter
Paste a JSON response and get GraphQL schema types for it. Every object becomes a type, arrays become lists, and fields that are always present get a !. Switch to input to generate input types for mutations.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Paste a JSON sample — ideally a real API response with several items in each array, so optional fields are found.
- Choose type for output types or input for mutation arguments (names get an Input suffix).
- Copy the schema into your .graphql file and rename Root to a meaningful name such as Book.
How it works
The sample is read into a shape: every key with every kind of value seen for it, with all objects of an array merged into one type.
- Field names that are valid GraphQL names are kept as they are; others (user-name) are rebuilt in camelCase with the JSON key in a # comment.
- Types are listed parent first: Root, then nested types in the order they appear.
- A top-level array gives a comment such as # Top level: [RootItem!]! — use that type for your query field.
Worked example
{"line_items":[{"sku":"A","qty":2},{"sku":"B"}]} gives:
type Root {
line_items: [LineItem!]!
}
type LineItem {
sku: String!
qty: Int
}
qty is missing from the second item, so it has no !, and the list type is named in the singular.
Tips
- GraphQL convention is camelCase field names; rename snake_case keys and map them in your resolvers if you like.
- Dates arrive as strings in JSON; consider a DateTime scalar instead of String.
- Reformat a schema you edited with the GraphQL formatter.
Frequently asked questions
How are JSON values mapped to GraphQL types?
Strings become String, true and false Boolean, whole numbers Int and other numbers Float (a mix of both becomes Float). Arrays become lists such as [String!]! and every object gets its own type, named after its key: author gives Author, reviews gives Review.
When does a field get the ! (non-null) mark?
When the value is never null in the sample and the key is present in every object of its array. A key that is missing in some objects, or null somewhere, stays nullable. Turn the option off to make every field nullable, which is the GraphQL default.
What is the JSON scalar in the output?
GraphQL has no any type, so a place that holds different kinds of values, only null, or an object with no keys becomes a custom scalar JSON, declared at the top. Your server needs a resolver for it — for example GraphQLJSON from the graphql-scalars package — or you can replace it with a real type.
Should IDs be Int or ID?
The tool cannot know that a number is an identifier, so id: 42 comes out as Int. GraphQL's Int is a signed 32-bit integer; for keys or large numbers change the type to ID (sent as a string) or Float by hand.