01What is JSON to GraphQL?
Writing a GraphQL schema by hand for an API you already have is slow. Paste a sample JSON object here and you get GraphQL SDL type definitions that describe its shape, ready to drop into a schema file. The top level becomes a type called Root. Every nested object becomes its own type, named after its key in PascalCase, so an address key produces an Address type. Arrays of objects become list types, and the item type takes the key's name with one trailing s removed. So users gives [User] and lineItems gives [LineItem]. That rule is simple string trimming, so a key like address_es or status will come out oddly. Before typing an array, the tool merges all of its elements. The item type therefore has every key seen in any element. A key that is missing or null in some elements stays nullable, while keys present in all of them get the ! non-null mark. Scalars come from the values, using the five built-in types the GraphQL specification defines. Whole numbers become Int, but the spec limits Int to 32 bits, so anything past 2,147,483,647 becomes Float. Decimals are Float, true and false are Boolean, and text is String. Two heuristics refine strings. A value that starts with a YYYY-MM-DD date becomes DateTime, and a scalar DateTime line is added at the top. A string under a key named id, or ending in Id, ID or _id, becomes ID. The ID rule only applies to strings, so a numeric userId stays Int. Here is a small worked case. The input {"users":[{"id":1,"name":"A"},{"id":2,"email":null}]} produces a Root type with users: [User]!, and a User type with id: Int!, name: String and email: String. name is nullable because the second user lacks it. Some cleanup keeps the output valid. Field names lose characters GraphQL doesn't allow, and a leading digit gets an underscore, so 9lives becomes _9lives. A type that would clash with a built-in scalar gets a Type suffix, so a string object becomes StringType. An empty object gets a placeholder _empty field, because the spec requires at least one field per object type. We checked the output with the reference graphql-js parser. Limits are worth a look. If two nested objects map to the same type name, the first one wins and the second shape is dropped. Empty and mixed arrays fall back to [String]. The tool writes types only, no queries, inputs or resolvers. A bare array at the top level is rejected.
Backend developers drafting a GraphQL schema from existing JSON responses, and gateway engineers wrapping REST APIs in GraphQL. The tool runs entirely in your browser, so your data never leaves your device.
02How to use JSON to GraphQL
- Paste a JSON object into JSON Input, or load the User profile, API response or Config object example.
- Read the generated SDL in the GraphQL Types panel. It updates as you type.
- Fix any error shown below the panels, such as invalid JSON or a top-level array.
- Click Copy Output, then rename Root and tighten types in your schema file.
- Use Reset to clear the input.
03Worked examples
- Input:
{"id":"u1","userId":42,"score":9.5,"active":true,"tags":["a"],"address":{"city":"Oslo"}} - Result:
type Root { id: ID! userId: Int! score: Float! active: Boolean! tags: [String]! address: Address! } type Address { city: String! } - Only the string under id becomes ID. userId holds a number, so it stays Int. The nested object gets its own type.
- Input:
{"users":[{"id":1,"name":"A"},{"id":2,"email":null}]} - Result:
type Root { users: [User]! } type User { id: Int! name: String email: String } - Array items are merged. name is missing from one user and email is null, so both stay nullable.
- Input:
{"createdAt":"2024-01-15T10:30:00Z","user_id":"u-9","width":300} - Result:
scalar DateTime type Root { createdAt: DateTime! user_id: ID! width: Int! } - A date-like string adds the DateTime scalar. user_id ends in _id so it becomes ID, while width is left alone.
- Input:
{"big":3000000000,"string":{"a":1},"9lives":true,"settings":{}} - Result:
type Root { big: Float! string: StringType! _9lives: Boolean! settings: Settings! } type StringType { a: Int! } type Settings { _empty: Boolean # placeholder: the sample object had no keys } - Too big for Int, a clash with a built-in scalar, a leading digit and an empty object are each handled so the SDL still parses.
- Input:
{"items":[],"meta":null,"count":3} - Result:
type Root { items: [String]! meta: String count: Int! } - An empty array defaults to [String] and null becomes a nullable String. Check both against real data.
- Input:
[1] - Result:
Error: Input must be a JSON object - The top level has to be an object, since it becomes the Root type.
04Common use cases
- Bootstrapping a schema for Apollo Server or GraphQL Yoga from an existing REST response
- Wrapping a third-party JSON API in a GraphQL gateway and needing the types quickly
- Writing schema-first types for a Pothos or Hasura project from a few sample records
- Documenting the shape of a webhook payload in SDL for a team that already reads GraphQL
- Spotting which fields are optional by pasting several array items and seeing which ones stay nullable
- Getting a first draft of types for a GraphQL code generator before refining them by hand
05Tips
- The ID heuristic only checks the key name on string values. An orderId holding a human-readable code may be better as String.
- Paste several array items rather than one. Keys missing from some items stay nullable, which is usually closer to reality.
- Watch for name collisions: two different objects both under a key called meta produce one Meta type, and the second shape is lost.
- Empty arrays and arrays with mixed value types become [String], so replace them with the real item type.
- Numbers above 2,147,483,647 turn into Float. For IDs or timestamps that big, a custom scalar or String is often a better fit.
06Related concepts
GraphQL SDL, Schema-first development, Type inference, Custom scalars, Nullability.
Frequently Asked Questions
What is JSON to GraphQL?
JSON to GraphQL is a free, browser-based developer tool on AIDToolStack. Convert JSON to GraphQL type definitions It requires no installation or sign-up and works entirely in your browser.
Is JSON to GraphQL free to use?
Yes. No sign-up, no fees and no usage cap.
Does JSON to GraphQL store my data?
No. It runs in your browser; nothing is uploaded.