Convert JSON Data to GraphQL Schema — Numio
Generates GraphQL SDL object types from sample JSON. The root becomes AutogeneratedMainType, each nested object or array of objects becomes a named type, and all array elements are merged into one type.
Drafting types for a GraphQL wrapper around an existing REST endpoint from one of its responses.
JSON
GraphQL
When to use it
- Drafting types for a GraphQL wrapper around an existing REST endpoint from one of its responses.
- Getting a starting schema for a mock server or schema-first prototype from sample data.
How to use
- Paste a JSON object, or an array of objects that are merged into one root type, into the left editor, or use the load-file button to open a UTF-8 file.
- Check the generated types: names come from the keys (posts becomes Posts) and scalars map to String, Int, Float or Boolean.
- Copy the SDL, then add ! for required fields, change id fields to ID, and rename AutogeneratedMainType.
JSON object
{
"id": "u_1",
"name": "Ada",
"age": 36,
"score": 9.5,
"nickname": null,
"tags": ["math"],
"address": { "city": "London" },
"posts": [{ "id": 7, "title": "Notes" }]
}GraphQL schema (SDL)
type AutogeneratedMainType {
id: String
name: String
age: Int
score: Float
nickname: String
tags: [String]
address: Address
posts: [Posts]
}
type Address {
city: String
}
type Posts {
id: Int
title: String
}Details and limitations
Fields are merged across all array elements. null and empty arrays become String and [String]; Int mixed with Float becomes Float, and other conflicts fall back to String.
Type names come from keys (posts becomes Posts). If the same key holds differently shaped objects, the later one is named after its parent (for example AB) instead of overwriting.
No ! (non-null), ID, Query type or input types are generated. Integers outside the 32-bit range are typed Float, because GraphQL Int is 32-bit.
Runs in your browser and the result is formatted with Prettier; invalid JSON shows the parse error.
FAQ
Can I convert a JSON array at the root?
Yes, if it holds objects: all elements are merged into AutogeneratedMainType, so fields that appear in only some elements are included. A root array of plain values is rejected because it has no fields.
Why is my id field String instead of ID?
Types come from the JSON value only: a string id becomes String and a number becomes Int. Change it to ID: by hand.
How are null values typed?
As String, since a null value carries no type. Replace it with a real sample value if the field is a number or object.