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

[ bsd3, json, library, program ] [ Propose Tags ]

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


[Skip to Readme]
Versions [faq] 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.2.1, 0.2.0.0, 0.2.1.0, 0.2.1.1, 0.2.1.2
Change log ChangeLog.md
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
Maintainer maintainer@obsidian.systems
Revised Revision 1 made by phadej at Tue Oct 8 19:24:34 UTC 2019
Category JSON
Source repo head: git clone git://github.com/obsidiansystems/aeson-gadt-th.git
Uploaded by abrar at Thu Mar 28 21:01:18 UTC 2019
Distributions NixOS:0.2.1.2
Executables readme
Downloads 995 total (248 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]

Modules

[Index]

Downloads

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

For package maintainers and hackage trustees


Readme for aeson-gadt-th-0.2.0.0

[back to package description]

aeson-gadt-th

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

Example Usage:

{-# LANGUAGE GADTs #-}
{-# 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 ()

Encoding:

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

Decoding:

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