deftools.io Developer Tools

JSON → GraphQL Schema

Convert JSON to GraphQL types. Paste a JSON object and get GraphQL schema type definitions with nullable/non-nullable fields.

About this tool

Generate GraphQL schema type definitions from any JSON object. Paste a JSON response from an API, a config file, or a sample payload and the tool derives GraphQL types — mapping strings, numbers, and booleans to the matching GraphQL scalars, nesting objects into named types, and wrapping arrays in list types. A Query type is added automatically so you can copy the result straight into an .graphql file.

Example input:

{"id":1,"name":"Ada","active":true}

Produces (with non-null and descriptions enabled):

"""Type generated from JSON — Root"""
type Root {
  """Example: 1"""
  id:     Int!
  """Example: Ada"""
  name:   String!
  """Example: true"""
  active: Boolean!
}

type Query {
  root: Root!
}

Toggle Non-null fields to emit the ! suffix on every field (assuming the key is always present). Turn off Include descriptions for a compact schema ready to paste into your SDL file. Nested objects and arrays of objects each become their own named type, and identical shapes are deduplicated automatically.

FAQ

How are JSON types mapped to GraphQL scalars?

Strings become GraphQL String, integers become Int, decimals become Float, and booleans become Boolean. The tool never emits a custom scalar — if your JSON value is a date string it will appear as String; rename it to a custom scalar (e.g. DateTime) in your final schema.

What does the Non-null option do?

When enabled, every field whose JSON value is not null gets the ! suffix (e.g. name: String!). Disable it to make all fields nullable — useful for partial API responses where keys may sometimes be absent.

Can it handle arrays of objects?

Yes. An array of objects like [{"id":1}] produces a list type [Post!] wrapping a named Post type for the element. Empty arrays fall back to [String] since the element shape is unknown. Mixed arrays (some strings, some objects) get [String] as a safe fallback.

Are duplicate shapes merged?

Yes. If two keys point to objects with identical field names and types (e.g. a "user" and an "author" that are both {id,name}), they share a single type definition rather than creating two identical ones. The type name comes from whichever key was encountered first.

What if I need Go structs instead of GraphQL types?

Use the <a href="/json-to-go">JSON to Go Struct</a> tool — paste the same JSON and get Go type definitions with json tags, omitempty, embedded structs, and pointer nullables, suitable for a .go file.

How do I share a JSON snippet?

Click the Share button to copy a URL with your JSON encoded in the hash. Anyone opening that link will see the same JSON and generated GraphQL types. URLs are capped at about 3,000 characters of JSON.

More developer tools

Copied!