aeson-gadt-th: Derivation of Aeson instances for GADTs

[ bsd3, json, library ] [ Propose Tags ]

Template Haskell for generating ToJSON and FromJSON instances for GADTs. See for examples.

[Skip to Readme]




Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,,,, 0.2.2, 0.2.3, 0.2.4,,, (info)
Change log
Dependencies aeson, aeson-gadt-th, base (>=4.11 && <4.13), dependent-sum (<, template-haskell, transformers [details]
License BSD-3-Clause
Copyright 2019 Obsidian Systems LLC
Author Obsidian Systems LLC
Revised Revision 2 made by abrar at 2020-10-05T17:56:13Z
Category JSON
Source repo head: git clone git://
Uploaded by abrar at 2019-03-28T21:01:18Z
Distributions NixOS:
Reverse Dependencies 2 direct, 0 indirect [details]
Executables readme
Downloads 5137 total (40 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for aeson-gadt-th-

[back to package description]


Provides Template Haskell expressions for deriving ToJSON and FromJSON instances for GADTs.

Example Usage:

{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}

import Data.Aeson
import Data.Aeson.GADT.TH

data A :: * -> * where
  A_a :: A a
  A_b :: Int -> A ()

data B c :: * -> * where
  B_a :: c -> A a -> B c a
  B_x :: B c x

deriveJSONGADT ''A
deriveJSONGADT ''B

main :: IO ()
main = return ()


encode A_a
> "[\"A_a\",[]]"


When decoding a JSON-encoded GADT, the result will be wrapped using Data.Some.This.

case (decode $ encode A_a) :: Maybe (Some A) of
  Nothing -> error "Couldn't decode
  Just (This A_a) -> putStrLn "it worked"
  Just (This A_b) -> putStrLn "wat"
> it worked