JSON to Haskell Record screenshot

JSON to Haskell Record

Turn a JSON sample into a Haskell data type in your browser. Absent and null fields stay distinct, and nothing is uploaded.

Privacy First
0 Runs
Updated 2026-11-06
No upload
Instant
No signup

What the JSON to Haskell generator does

Each object becomes a record with a Generic instance and both aeson instances. Haskell record selectors share one namespace across the whole module, so two records that both contain a name would collide; the DuplicateRecordFields pragma is emitted for exactly that reason, and without it the generated module does not compile. Absent and null both become Maybe. Field names are snake_case, because camelCase keys would otherwise need every selector renamed by hand.

How to use it

JSON to Haskell Record: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Haskell data type below.

Worked example

Input:

{
  "id": 42,
  "displayName": "Ada Lovelace",
  "active": true,
  "score": 9.5,
  "tags": [
    "math",
    "engine"
  ],
  "address": {
    "city": "London",
    "country": "GB"
  },
  "projects": [
    {
      "name": "Analytical Engine",
      "year": 1843
    },
    {
      "name": "Note G",
      "year": 1843,
      "notes": "first published algorithm"
    }
  ],
  "nickname": null
}

Output:

-- Generated from a JSON sample in the browser by AllTools — nothing was uploaded.
-- Record selectors share one namespace in Haskell, so DuplicateRecordFields is
-- required for two records that both contain `id` or `name`.
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}

module Model where

import Data.Aeson (FromJSON, ToJSON, Value)
import GHC.Generics (Generic)

data Root = Root
  { id :: Int
  , display_name :: String
  , active :: Bool
  , score :: Double
  , tags :: [String]
  , address :: Address
  , projects :: [Project]
  , nickname :: Maybe (Value)
  } deriving (Show, Eq, Generic)

instance FromJSON Root
instance ToJSON Root

data Address = Address
  { city :: String
  , country :: String
  } deriving (Show, Eq, Generic)

instance FromJSON Address
instance ToJSON Address

data Project = Project
  { name :: String
  , year :: Int
  , notes :: Maybe (String)
  } deriving (Show, Eq, Generic)

instance FromJSON Project
instance ToJSON Project

Why it runs in your browser

The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns Haskell data type; reloading the page discards both.

Each object becomes a record with a Generic instance and both aeson instances. Haskell record selectors share one namespace across the whole module, so two records that both contain a name would collide; the DuplicateRecordFields pragma is emitted for exactly that reason, and without it the generated module does not compile. Absent and null both become Maybe. Field names are snake_case, because camelCase keys would otherwise need every selector renamed by hand.

Turn a JSON sample into a Haskell data type in your browser. Absent and null fields stay distinct, and nothing is uploaded.

How to use it

JSON to Haskell Record: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Haskell data type below.

Why it runs in your browser

The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns Haskell data type; reloading the page discards both.

What to Expect

Best for

  • Converting JSON to Haskell data type when the data is already on screen.

What this tool keeps

  • Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere.

Sample input

{ "id": 42, "displayName": "Ada Lovelace", "active": true, "score": 9.5, "tags": [ "math", "engine" ], "address": { "city": "London", "country": "GB" }, "projects": [ { "name": "Analytical Engine", "year": 1843 }, { "name": "Note G", "year": 1843, "notes": "first published algorithm" } ], "nickname": null }

Sample output

-- Generated from a JSON sample in the browser by AllTools — nothing was uploaded. -- Record selectors share one namespace in Haskell, so DuplicateRecordFields is -- required for two records that both contain `id` or `name`. {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} module Model where import Data.Aeson (FromJSON, ToJSON, Value) import GHC.Generics (Generic) data Root = Root { id :: Int , display_name :: String , active :: Bool , score :: Double , tags :: [String] , address :: Address , projects :: [Project] , nickname :: Maybe (Value) } deriving (Show, Eq, Generic) instance FromJSON Root instance ToJSON Root data Address = Address { city :: String , country :: String } deriving (Show, Eq, Generic) instance FromJSON Address instance ToJSON Address data Project = Project { name :: String , year :: Int , notes :: Maybe (String) } deriving (Show, Eq, Generic) instance FromJSON Project instance ToJSON Project

Frequently asked questions

How do I use the json to haskell record?

JSON to Haskell Record: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the Haskell data type below.

Is my input uploaded?

No. The text is parsed on this page with JavaScript and is never posted to a server.

Is there a size limit?

Yes: 5 MB per run. Larger input is refused with a message rather than freezing the tab.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.