Loading JSON to GraphQL Converter...
How to Turn JSON into a GraphQL Schema
Paste or upload your JSON
Paste a JSON object or a list of objects into the left editor, upload a .json file, or press Sample to load an example. A real API response works best, because the types come from the values in it. Any valid JSON works. If yours came out of an API and is hard to read, format the JSON first.
Example: JSON Input
A user record with a list of posts:
{
"id": 1,
"name": "Elara Quinn",
"email": "[email protected]",
"isActive": true,
"posts": [
{
"id": 101,
"title": "Hello World",
"published": true
}
]
}Let the types be worked out
Each JSON object becomes a GraphQL type, lists become list types, and every item of a list is looked at before a field is marked non-null. The schema updates about half a second after you stop typing. The rules follow the GraphQL type system, including lists and non-null.
Example: GraphQL Schema Output
What the converter writes for the JSON above. The posts object turned into its own Post type:
type Query {
root: Root!
}
type Root {
id: Int!
name: String!
email: String!
isActive: Boolean!
posts: [Post!]!
}
type Post {
id: Int!
title: String!
published: Boolean!
}Check the notes at the top
If something needed a decision, a short comment block at the top says so: long whole numbers that got the Long scalar, fields that mix types and became JSON, and keys that had to be renamed. The output always includes a small Query type, because a schema without one fails validation. You can check the result in the GraphQL schema validator.
Copy or download the schema
Copy the SDL or download it as schema.graphql, then rename Root and the starter Query to fit your API and add your own queries and mutations. Need TypeScript types from the finished schema? Run it through GraphQL to TypeScript, or tidy it up with the GraphQL formatter.
Frequently Asked Questions
How does the converter decide each field type?
From the values in your sample. Text becomes String, true and false become Boolean, whole numbers that fit in 32 bits become Int, numbers written with a decimal point or exponent (14.50, 1.0, 1e3) become Float, and nested objects become their own type named after the key. Text that only looks like a number, such as "00501", stays a String.
Why does a long ID come out as Long instead of Int?
GraphQL's Int is a signed 32-bit number, so it stops at 2147483647. An ID like 8901240544102066246 would be rejected by any server that follows the spec, and turning it into a Float would quietly round it. Whole numbers past 32 bits get a custom Long scalar, and numbers too long even for 64 bits get BigInt. Both are declared at the top of the output, and libraries such as graphql-scalars ship ready implementations.
When is a field marked non-null with an exclamation mark?
Only when every object in the sample has that key and none of them hold null. If you paste a list, all items are compared, so a key that shows up in just some of them is left nullable. The same goes for list items: [Post!]! means the list itself and every item in it were always present.
What happens to keys that are not valid GraphQL names?
GraphQL names can only use letters, digits and underscores, can't start with a digit and can't start with two underscores. A key like "first-name" or "2nd" gets a cleaned-up field name (first_name, _2nd), and the original key is written into the field description so you can map it in a resolver. If two keys would end up with the same name, the second one is numbered.
Why is there a JSON scalar in my schema?
GraphQL has no "any" type. When a field held different kinds of values in your sample (a number in one item and text in another), or was only ever null or an empty list, the converter can't pick a real type, so it uses a JSON scalar and says which fields in the notes. Replace it with the real type once you know it.
Can I paste a JSON array or a REST response with many records?
Yes. A top-level list is read item by item and the starter Query returns it from an items field. The more records you paste, the better the nullability, because a field is only non-null if every record has it. A single plain value such as 42 has no fields, so you get a short message instead of a schema.
Is my JSON uploaded anywhere?
No. The schema is built in your browser while you type, nothing is sent to a server, and nothing is kept. Reload the page and the editor starts empty.
Related Tools
GraphQL Query Formatter
Format and beautify GraphQL queries and schemas with syntax highlighting
GraphQL Schema Validator
Validate GraphQL schemas with syntax and structure checking
GraphQL Fixer
Fix broken GraphQL queries and schemas automatically, repair syntax errors and malformed types
GraphQL to TypeScript
Generate TypeScript types from GraphQL schemas and queries
GraphQL Minifier
Compress and optimize GraphQL queries for production
GraphQL to JSON Schema
Convert GraphQL schemas to JSON Schema format