DevBolt
Processed in your browser. Your data never leaves your device.

How do I generate a GraphQL schema from JSON?

Paste JSON data and the tool infers GraphQL types with automatic type detection (String, Int, Float, Boolean, ID, DateTime). Nested objects become separate types. Options include Query/Mutation generation, non-null fields, and descriptions. Download as .graphql or copy. Everything runs in your browser.

JSON to GraphQL type
Input
{"id":1,"name":"Alice","email":"a@b.com"}
Output
type Root {
  id: Int!
  name: String!
  email: String!
}
← Back to tools

JSON to GraphQL Schema Generator

Generate GraphQL schema definitions from JSON data. Automatically infers types, detects IDs, dates, and nested objects. Optionally generates Query and Mutation types.

About JSON to GraphQL Schema

  • Infers GraphQL scalar types (String, Int, Float, Boolean, ID) from JSON values automatically.
  • Detects UUIDs and ID-like fields → ID, dates → DateTime /Date custom scalars.
  • Nested objects become separate GraphQL types. Arrays of objects are merged for complete field coverage.
  • Optionally generates Query type (get by ID, list all) and Mutation type (create, update, delete) with input types.
  • Download the schema as a .graphql file ready for your server.
  • Everything runs in your browser — no data is sent over the network.

Tips & Best Practices

Pro Tip

Use custom scalar types for dates and IDs

GraphQL has no built-in Date or DateTime type. When generating a schema from JSON with date strings, define custom scalars (scalar DateTime) rather than using String. This enables proper validation and serialization with libraries like graphql-scalars.

Common Pitfall

Nullable vs non-null defaults matter for schema evolution

Making all fields non-null (String!) in your generated schema is strict but dangerous — adding a new nullable field later is a breaking change for clients expecting non-null. Start with nullable fields by default and only add ! for fields you're certain will always be present.

Real-World Example

Generate a schema from your REST API responses

Migrating from REST to GraphQL? Paste your existing REST JSON responses to get a starting GraphQL schema. This captures the current data shape and lets you iterate on the schema design before writing resolvers.

Security Note

Limit query depth to prevent denial-of-service

Deeply nested GraphQL types (User → Posts → Comments → Author → Posts...) allow recursive queries that can overwhelm your server. After generating your schema, configure query depth limiting (typically 7-10 levels max) using graphql-depth-limit or similar middleware.

Frequently Asked Questions

How do I generate a GraphQL schema from JSON data?
Paste your JSON data into DevBolt's converter and it automatically infers GraphQL type definitions from the structure. Object keys become fields, nested objects become separate GraphQL types, and arrays infer element types. The tool generates complete SDL output including type definitions, Query type with get-by-ID and list operations, and optional Mutation type with create/update/delete operations. Custom scalars like DateTime and Date are detected from ISO string patterns. All generation runs in your browser.
What GraphQL types are inferred from JSON values?
String values become String, integers become Int, floating-point numbers become Float, booleans become Boolean, and fields named id or containing UUID patterns become ID. ISO date strings become DateTime or Date custom scalars. Nested objects become separate named GraphQL types. Arrays of primitives become lists like [String]. Arrays of objects are merged to capture all possible fields. Null values make the field nullable by omitting the ! non-null modifier.
How does the converter handle nested objects and arrays?
Nested objects are extracted into separate named GraphQL types based on the parent field name. For example, a user field containing an address object generates both a User type and an Address type with the user field typed as Address. Arrays of objects merge all array elements to build a complete field set, handling cases where different objects have different keys. Deeply nested structures produce a type hierarchy that mirrors the JSON structure faithfully.

Related Generate Tools