Xerobit

JSON to GraphQL Converter

Paste a JSON object to generate GraphQL type definitions. The converter infers scalar types, creates named types for nested objects and handles arrays and null values deterministically. It runs entirely in the browser so nothing is uploaded.

GraphQL Schema

type Root {
  active: Boolean!
  id: Int!
  name: String!
}

How to use the json to graphql converter

  1. Paste your JSON object into the input area.
  2. Set a root type name (defaults to Root).
  3. The GraphQL schema updates automatically as you type.
  4. Copy the generated type definitions into your project.

How the conversion works

The converter maps each JSON value to a GraphQL scalar or custom type. Whole numbers within the 32-bit range become Int, while decimals and larger whole numbers become Float because GraphQL Int is a signed 32-bit type. Booleans map to Boolean, and strings map to String.

When a value is null, the field is marked nullable by omitting the exclamation mark. Non-null values receive the ! suffix. For example, given {"age": 30, "bio": null}, the output is:

type Root { age: Int! bio: String }

Nested objects generate their own named types. The key is capitalized using PascalCase to form the type name. Arrays inspect every element to determine the inner type; empty arrays default to [String!].

Type mapping reference

This table shows how common JSON values translate into GraphQL types during a json to graphql conversion.

JSON ValueGraphQL TypeNotes
42Int!Whole numbers only
3.14Float!Any decimal number
trueBoolean!True or false
"hello"String!Any text value
nullStringNullable, no exclamation mark
[1, 2][Int!]!Inferred from all elements
[][String!]!Defaults to String when empty
{"x": 1}X!Generates a new named type

Handling nested objects and arrays

When the converter encounters a nested object, it extracts it into a separate type definition. The field name is transformed to PascalCase to serve as the type name. This keeps the schema flat and readable, which is standard practice for GraphQL APIs.

Arrays are handled by examining every element. If the array contains objects, one shared type is generated by merging them, and keys that are missing or null in some elements become nullable. If the array is empty, the tool defaults to [String!]! because GraphQL requires a concrete inner type for lists. You can adjust this manually after generation if your data uses a different type.

Keys are sorted alphabetically in the output to ensure deterministic results. Running the same JSON through the converter always produces identical schema text, making it safe to use in automated pipelines or build scripts.

Common edge cases

A few situations require attention when converting JSON to GraphQL types. First, JSON allows duplicate keys in some parsers, but the last value wins. The converter processes whatever JSON.parse returns, so duplicate keys resolve to the final occurrence.

Second, very large integers beyond JavaScript safe integer limits may lose precision before the converter even sees them. If your API uses 64-bit identifiers, consider passing them as strings in the source JSON so they map cleanly to String!.

Third, mixed-type arrays like [1, "two"] are not supported natively in GraphQL. The converter falls back to a custom scalar JSON (declared at the top of the output) for such lists. If you want a stricter schema, define a union type manually after conversion.

Worked examples

ExampleInputResult
Simple userJSON input: {"id": 1, "name": "Alice", "active": true}; Root type name: Usertype User { / active: Boolean! / id: Int! / name: String! / }
Nested addressJSON input: {"user": "Bob", "address": {"street": "123 Main St", "zip": "90210"}}; Root type name: Profiletype Address { / street: String! / zip: String! / } / type Profile { / address: Address! / user: String! / }
Array of tagsJSON input: {"title": "Post", "tags": ["news", "tech"]}; Root type name: Posttype Post { / tags: [String!]! / title: String! / }

FAQ

Does this tool upload my JSON to a server?

No. The json to graphql conversion happens entirely in your browser using JavaScript. Nothing is sent over the network.

How are null values handled?

A null value produces a nullable field without the exclamation mark. The scalar type defaults to String since JSON null carries no type information.

What happens with empty arrays?

Empty arrays default to [String!]! because GraphQL requires a concrete inner type. Change it manually if your data uses a different type.

Can I convert a JSON array at the root level?

No. The root input must be a JSON object so the converter can generate a named GraphQL type. Wrap your array in an object first.

Are the generated types production-ready?

They provide a solid starting point. You should review field names, adjust nullable markers and add descriptions before deploying to a GraphQL server.

How are nested objects named?

The key containing the nested object is converted to PascalCase and used as the new type name. For example, a key called billing_address becomes BillingAddress.