JSON to GraphQL Schema Generator — Free Online Tool
Generate a GraphQL schema (SDL) from any JSON object using AI. Creates type definitions with proper scalar types, nested types, and list fields. Free, no sign-up.
Related Guides
JSON to GraphQL Schema Generator — Free Online Tool
About JSON to GraphQL Schema Generator — Free Online Tool
JSON to GraphQL Schema converts a JSON object or array into a typed GraphQL SDL (Schema Definition Language) schema, inferring field names and scalar types automatically. Developers use it to bootstrap GraphQL APIs from existing REST responses, database exports, or mock data without writing schema boilerplate by hand.
JSON to GraphQL Type Mapping
| JSON Type | JSON Example | GraphQL SDL Type | Notes |
|---|---|---|---|
| string | "hello" | String | Maps to built-in scalar; use ID for identifier fields |
| number (integer) | 42 | Int | Integers within ±2^31; use Float if fractional values appear |
| number (float) | 3.14 | Float | IEEE 754 double; GraphQL Float covers all JS numbers |
| boolean | true | Boolean | Direct 1-to-1 mapping |
| null | null | String (nullable) | Null alone cannot determine type; field is inferred as nullable |
| object | {"id":1} | type TypeName { ... } | Nested objects become named types derived from the field name |
| array of objects | [{"id":1}] | [TypeName!] | Generates a list type; inner type inferred from first element |
| array of scalars | [1,2,3] | [Int] | Scalar arrays map to list of the inferred scalar type |
| empty array | [] | [String] | Type unknown; defaults to [String] — override manually |
| ISO date string | "2024-01-01T00:00:00Z" | String | No native Date scalar; add a custom scalar or use String |
GraphQL Schema Generation: Format Comparison
| Approach | Input | Output | Pros | Cons |
|---|---|---|---|---|
| JSON to GraphQL (this tool) | JSON object/array | SDL type definitions | Zero config, instant from real data | No resolvers, no directives, no custom scalars |
| GraphQL Introspection | Running GraphQL endpoint | Full schema JSON | 100% accurate, includes directives | Requires live server |
| Prisma schema to GraphQL | Prisma .schema file | SDL + resolvers | Type-safe DB integration | Prisma-specific workflow |
| OpenAPI to GraphQL | OpenAPI/Swagger YAML | SDL + mutations | REST migration path | Complex spec required |
| Code-first (Apollo/TypeGraphQL) | TypeScript decorators | SDL at runtime | Full type safety in code | Requires writing TS classes first |
| Hasura auto-schema | PostgreSQL tables | SDL + subscriptions | Instant from DB | Tied to Hasura platform |
Frequently Asked Questions
How does JSON to GraphQL schema handle nested objects?
Each nested JSON object is converted into a separate named GraphQL type, with the field name used (capitalized) as the type name. For example, a field called `address` containing an object becomes a type `Address` in the SDL. The parent type then references it as `address: Address`. If multiple fields share the same nested shape, they each generate their own type definition — you may want to deduplicate manually.
What GraphQL type does a JSON number map to — Int or Float?
The generator inspects the value: integers (no decimal point, within ±2,147,483,647) map to `Int`, and numbers with a decimal point map to `Float`. If a field contains mixed integers and floats across array items, most tools will widen the type to `Float` to avoid data loss. Always verify numeric fields in your schema before using it in production.
Can I generate a GraphQL mutation or query from JSON, not just a type?
JSON-to-GraphQL tools generate SDL type definitions only — they produce `type` blocks that describe your data shape. Queries and mutations are separate concerns and require you to define them manually in your schema. Once you have the generated types, you can write `type Query { getUser(id: ID!): User }` yourself, or use a framework like Hasura or Nexus that scaffolds queries from types automatically.
Why are all my fields generated as nullable in the GraphQL schema?
JSON alone cannot tell you whether a field is always present or sometimes omitted, so generators default to nullable (no `!` suffix) to avoid breaking queries on incomplete data. To mark a field non-null, add the `!` suffix manually in the SDL after generation — for example, change `id: Int` to `id: Int!`. Using an array of multiple JSON samples (if your tool supports it) allows the generator to detect fields that appear in every object and mark them required.
How do I handle JSON fields with an ISO date string in GraphQL schema?
GraphQL's built-in scalars do not include a Date or DateTime type, so date strings are generated as `String`. The standard practice is to declare a custom scalar — `scalar DateTime` — at the top of your SDL and change the field type from `String` to `DateTime`. Libraries like `graphql-scalars` (npm) provide ready-to-use DateTime, Date, and JSON scalars with validation and serialization already implemented.
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.