JSON to GraphQL schema
Useful when building a GraphQL server over an existing API: start the type definitions from here instead of from scratch.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter json input and root type name.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
String, Int, Float, Boolean and [T] lists, with a type per object. A field that is always present and never null gets !. GraphQL Int is 32-bit, so numbers above 2147483647 become Float with a comment, and mixed values use a JSON scalar.
Example
Inputs: Root type name = Root. Result: Generated code: type Root { id: Int! name: String! email: String! isActive: Boolean! # JSON key: "is_active" balance: Float! tags: [String!]! address: Address! orders: [Order!]! } type Address { city: String! postalCode: String! # JSON key: "postal_code" } type Order { orderId: String! # JSON key: "order_id" total: Float! coupon: String }; Types generated: 3; Fields: 13.
{
"id": 1024,
"name": "Sara Ahmed",
"email": "sara@example.com",
"is_active": true,
"balance": 1520.75,
"tags": ["vip", "riyadh"],
"address": { "city": "Riyadh", "postal_code": "12211" },
"orders": [
{ "order_id": "A-1", "total": 99.5, "coupon": "EID10" },
{ "order_id": "A-2", "total": 120, "coupon": null }
]
}type Root {
id: Int!
name: String!
email: String!
isActive: Boolean! # JSON key: "is_active"
balance: Float!
tags: [String!]!
address: Address!
orders: [Order!]!
}
type Address {
city: String!
postalCode: String! # JSON key: "postal_code"
}
type Order {
orderId: String! # JSON key: "order_id"
total: Float!
coupon: String
}Limits and caveats
- The JSON scalar needs a server-side definition, such as the one in graphql-scalars.
- GraphQL does not rename keys, so a renamed field needs a resolver that reads the original key.
Questions about this tool
What does ! after a type mean?
The field never returns null. It is added only to keys present in every item with no null value.
Why did a large number become Float?
GraphQL Int is limited to 32 bits, while Float holds whole numbers exactly up to 2 to the power of 53.
Is my JSON sent to a server?
No. The conversion runs in your browser and the JSON never leaves your device.
