JSON to GraphQL Types

Infer GraphQL types from JSON.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Paste a JSON object and get a GraphQL type definition (SDL) with one field per key. Numbers map to Float, arrays to lists, and nested objects to a JSON scalar that you must define yourself.

How to use

1
Step 1
Paste a sample JSON object.
2
Step 2
Press Run.
3
Step 3
Copy the type and rename Root, then declare the JSON scalar or replace it with real types.

How it works

Keys become fields: strings become String, integers and decimals both become Float, booleans become Boolean, arrays become [T] using the first item, and nested objects become JSON. The type is named Root. Fields are nullable, since the tool never adds a trailing exclamation mark.

Worked example

A user with a nested object

Input
{"id":1,"name":"Ada","score":9.5,"tags":["a"],"owner":{"x":1}}
Output
type Root { id: Float name: String score: Float tags: [String] owner: JSON }
Walkthrough
id is Float because integers and decimals are not distinguished; change it to Int or ID. owner is JSON because nested objects are not expanded.

Limitations

  • No Int, ID or non-null (!) types are inferred.
  • Nested objects are not turned into their own types.
  • The JSON scalar is not declared in the output.
  • Only the first array item is used.

Questions

How do I generate a GraphQL type from JSON?
Paste the object and press Run to get SDL you can edit.
Why are my integers Float?
The generator treats all numbers as Float. Change fields to Int or ID manually.
What does JSON mean in the output?
It marks a nested object. Define a custom JSON scalar or write a proper type for it.
Are fields non-null?
No. All fields are nullable until you add !.

Features

  • Lists from arrays
  • Float, String, Boolean mapping
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Learn Regular Expressions - Crash Course

    freeCodeCamp.org

    Regex primer for tester and explainer pages.

    Watch on YouTube
  • SQL Tutorial - Full Database Course

    freeCodeCamp.org

    JSON often lands next to SQL exports when debugging data pipelines.

    Watch on YouTube