JSON to GraphQL Schema Generator
Last updated:
Jsonic's JSON to GraphQL Schema Generator converts a JSON object into GraphQL SDL (Schema Definition Language) type definitions instantly in your browser. Fields with non-null values receive the ! non-null marker; fields with null values are left nullable. JSON strings map to String, integers to Int, decimals to Float, booleans to Boolean, and arrays to [Type!]! list types. Nested objects each generate a separate named type defined above the type that references it. A type Query block with a root field is appended automatically so the schema is immediately usable. All processing runs client-side — no data is uploaded.
How to convert JSON to a GraphQL schema
- Paste your JSON object into the left panel, or click Example to load a sample.
- Optionally change the root type name (default: Root).
- Click Generate.
- Copy the SDL output from the right panel.
- Paste the SDL into your schema.graphql file or as the typeDefs string in Apollo Server.
FAQ
What GraphQL SDL version does this generate?
The tool generates SDL per the June 2018 GraphQL specification. The output is compatible with Apollo Server, graphql-js, Pothos, Strawberry, and any other GraphQL implementation that follows the spec. Non-null fields use the ! syntax, list types use bracket notation, and each object type is declared with the type keyword.
How are JSON types mapped to GraphQL types?
JSON strings map to String, JSON integers (whole numbers) map to Int, JSON decimals map to Float, JSON booleans map to Boolean, JSON null causes the field to be nullable (no ! suffix), JSON arrays map to [Type!]! (a non-null list of non-null elements), and JSON objects each generate a separate named GraphQL type.
How is nullability determined?
Any field whose JSON value is null is treated as nullable and rendered without the ! non-null marker. Every other field — string, number, boolean, array, or nested object — is treated as non-null and rendered with !. If you know a field can sometimes be null in production even if the sample does not show it, remove the ! suffix manually after generating.
How do nested objects work?
Each nested JSON object generates a separate named GraphQL type. The type name is derived from the field name converted to PascalCase. Nested types are emitted before the type that references them, so the SDL is ordered correctly. For example, a field "address": { "city": "Paris" } produces an Address type with a city: String! field, and the parent type references it as address: Address!.
Can I use this with Apollo Server?
Yes. Copy the generated SDL and paste it directly as the typeDefs string in Apollo Server: const server = new ApolloServer({ typeDefs, resolvers }). Alternatively, save the SDL to a schema.graphql file and load it with gql or a file loader. The generated schema includes a type Query block so Apollo Server starts without requiring you to add one manually.
What about unions and interfaces?
This tool generates simple object types from the JSON structure it observes. GraphQL unions (used when a field can return different types) and interfaces (shared field sets across types) cannot be inferred from a JSON sample alone and require manual schema design. After generating the base types, you can introduce union and interface declarations by hand to model polymorphic relationships in your API.