Input

Output

What is the GraphQL to JSON Sample tool?

Mocking a GraphQL API in your test suite usually means writing fake data by hand for every type — boring, brittle, and the schema drifts away from your fixtures within a sprint or two. This page reads your GraphQL schema definition language and emits a JSON document that matches it. Paste your SDL on the left, and the right pane gives you a populated JSON object: every field of the Query type filled in, lists filled with two elements, enums set to their first value, and custom scalars like DateTime or URL mapped to sensible defaults.

There is no parser dependency loaded into the page — the SDL walker is hand-written, ~600 lines, and it covers every construct that shows up in a real schema: type, interface, union, enum, input, scalar, list and non-null modifiers, and self-referential types. The output is plain JSON per RFC 8259, two-space indented, ready to drop into a fetch mock or a Postman example response. Fields named email, name, phone, currency, or status get value samples that fit; everything else falls back to a generic "sample text".

Everything happens in your browser. Your schema never leaves the page, no network call is made, and the conversion is instant.

How to Use the GraphQL to JSON Sample Tool

Three quick steps. The buttons described below are the actual buttons on this page.

1

Paste, Upload, or Load a Sample

Paste a GraphQL schema into the left Input panel — conversion is automatic about a third of a second after you stop typing, so there is no Convert button. Click Upload for a .graphql or .gql file, or hit Sample to load a realistic e-commerce Order schema. A typical input looks like this:

type Query { order(id: ID!): Order } type Order { id: ID! customer: Customer! items: [OrderItem!]! total: Money! status: OrderStatus! placedAt: DateTime! }

Both server-style schemas (with type Query { ... }) and standalone type files work. The walker picks Query as the root if it exists, otherwise the first object type. The shapes accepted match what tools like graphql-js parse at startup.

2

Read the JSON Output

The right Output panel renders the JSON sample with two-space indentation. Object types become objects. Lists become two-element arrays. Enums become their first value as a string. Custom scalars get sensible defaults — DateTime becomes an ISO-8601 timestamp, URL becomes "https://example.com/...", JSON becomes {}. Self-referential types (type Person { friends: [Person!]! }) are capped at depth 4 and truncate with null so the page never hangs.

3

Copy or Download

Hit Copy to grab the JSON for a fixture file, mock server, or fetch stub. Hit Download to save as sample.json. The clear button on the input panel resets you to a blank state. Conversion happens entirely client-side — your schema never leaves the page.

When You'd Actually Use This

Mock GraphQL Server Fixtures

You are spinning up a mock backend with json-graphql-server or a Apollo Server mock and you need a starter JSON file shaped like your schema. Paste the SDL, copy the output, and you are 80% of the way there — tweak names and IDs, ship the fixture.

Postman / Insomnia Example Responses

Documenting a GraphQL endpoint in Postman or Insomnia means filling in an example response body for every operation. Generate the JSON shape from the type, paste it into the example, edit the values to match the test case. Beats hand-writing nested objects from scratch.

Frontend Type Drafting

When the backend ships a new GraphQL type, the frontend often needs a sample payload to wire up the UI before the endpoint is real. Convert the schema to JSON, drop it into a fixture, and build the components against the fixture. Swap to live data when the API is ready.

Schema Exploration

Reading a 300-line SDL is fine; seeing what an actual response looks like is faster. The JSON sample makes the schema concrete — you can immediately tell which fields are nested, which are arrays, and where the enums live. Useful onboarding aid for engineers new to a service.

Common Questions

Does it execute the query against a real server?

No. The page only generates a sample document that conforms to the schema shape. There is no network call. If you need to hit a real GraphQL endpoint, use GraphiQL or any GraphQL client.

Why does my self-referential type stop after a few levels?

There is a recursion cap at depth 4. A schema like type Person { friends: [Person!]! } would otherwise generate an infinitely nested object. Past the cap the value becomes null so the JSON stays finite and pretty-printable.

Which root type does it use?

It looks for type Query first. If that is missing, it picks the first object type defined in the schema (skipping input types). You can swap any type to the top by reordering your SDL.

Are custom scalars handled?

Yes. Common ones (DateTime, Date, Time, URL, Email, JSON, BigInt) get sensible defaults baked in. Anything else falls back to a generic placeholder string. If your scalar should map to something specific, edit the output by hand — it is just JSON.

Is the JSON valid against my schema?

It is shape-valid: every required field is filled, types line up with their declared scalar/object/list, enums use a real enum value. It is not semantically valid (the email is not a real email, the order ID is not a real ID). Use it as a fixture starting point, not a substitute for tests.

Is my schema sent to a server?

No. Conversion runs entirely in your browser. Nothing is uploaded, nothing is logged. Safe to paste internal or unreleased schemas.

Other GraphQL and JSON Tools

Generating a sample is one part of the GraphQL workflow. These tools cover the rest: