HCODX/JSON to Haskell
100% browser-based · Nested types · Haskell-idiomatic naming

JSON to Haskell

Convert any JSON object into a Haskell data type with record syntax. Nested objects become separate types, names are converted to idiomatic Haskell casing, and the whole thing runs locally in your browser — no upload, no API key, no signup.

JSON input
Haskell output
Generator options
JSON Formatter
Input size
0 B
Output size
0 B
Output lines
0
Status
Ready
Example

JSON in, Haskell out

The generator reads each key, infers a type from the sample value, and emits a typed Haskell structure with idiomatic naming.

JSON input
{
  "id": 1,
  "name": "Alice",
  "email": "alice@example.com"
}
Haskell output
data Root = Root
  { rootId :: Int
  , rootName :: String
  , rootEmail :: String
  } deriving (Show, Eq)
Use cases

What you'll use this for

Skip the boilerplate. Drop a JSON sample in, get back ready-to-paste Haskell types with sensible field names and structure.

API client scaffolding

You found a JSON response in the docs. Paste it here, get types you can drop into your client.

Config & fixtures

Generate types for config files, test fixtures, or any structured data you read at runtime.

Cross-language porting

Port a schema from another language by going through JSON as the lingua franca.

Private, local-only

JSON never leaves your browser. No upload, no API key, no signup.

Step by step

How to generate Haskell from JSON

1

Paste your JSON

Drop a real sample into the left editor. The richer the example, the better the inferred types.

2

Set the root type name

Default is Root. Use whatever makes sense — User, ApiResponse, etc.

3

Click Generate

Or leave auto-generate on. Output appears instantly on the right.

4

Copy or download

Copy to clipboard or save as .hs and drop it into your project.

FAQ

Frequently asked questions

Nested objects become their own separate types (or classes/structs/records). The top-level object references each nested type by name, and each is generated independently so you can compose or extract as needed.

JSON does not carry "optional" as a concept — only present-or-absent keys. Generate the output from an example that contains the optional fields and treat them as required (or hand-edit afterwards). Round-trip safety is up to your downstream code.

Yes. No signup, no limits, no ads, no upload. Everything runs in your browser.

Each leaf value gets a type based on its sample: strings stay strings, integers vs. floats are distinguished by whether the JS value is an integer, booleans stay booleans, and arrays use the first element\u2019s type. Nested objects become new typed records.

No — this generator is one-way (JSON to type definition). It produces type signatures, not parsing/serialization code. Pair it with your language\u2019s native JSON library.

About

About this generator

This tool inspects a JSON example and emits a Haskell data type with record syntax. It walks the value tree once — every nested object becomes its own type, and the parent references it by name. Field names are converted from JSON’s camelCase or snake_case into the idiomatic style for Haskell.

Type inference rules

  • Strings stay as the language’s native string type.
  • Numbers are split into integers vs. floats by checking whether the JS value Number.isInteger.
  • Booleans become the language’s native boolean.
  • Arrays use the first element’s type. Empty arrays fall back to a generic placeholder.
  • Nested objects become a separate generated type, referenced by name.
  • Nulls are mapped to the closest "maybe / optional / any" equivalent.

Limits

  • One-way only. This generator does not produce parsing or serialization code — just the type definitions.
  • Inferred from your sample. If a field is optional, include it in the example; otherwise the generator can’t see it.
  • Heterogeneous arrays (different types per element) are not detected — only the first element’s type is used.
Related

Related tools