aeson-dependent-sum: JSON encoding/decoding for dependent-sum

[ data, dependent-types, gpl, json, library ] [ Propose Tags ]

Newtype wrappers around Data.Dependent.Sum.DSum, for use with -XDerivingVia. These wrappers are helpful when parsing JSON objects where certain keys determine the type of the deserialised value.

[Skip to Readme]


[Index] [Quick Jump]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],
Change log
Dependencies aeson (>=2.0 && <2.2), base (>=4.9 && <4.18), constraints-extras (>= && <0.4), dependent-sum (>= && <0.8), some (>= && <1.1), vector (>= && <0.14) [details]
License GPL-3.0-or-later
Copyright (c) 2022 Jack Kelly
Author Jack Kelly
Category Data, Dependent Types, JSON
Home page
Bug tracker
Source repo head: git clone
Uploaded by jack at 2022-08-27T10:40:29Z
Downloads 108 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-08-27 [all 1 reports]

Readme for aeson-dependent-sum-

[back to package description]

aeson-dependent-sum status GPLv3

If you need to (de)serialise JSON from/to a dependent sum (from the dependent-sum package), this library provides newtype wrappers which you can use with the -XDerivingVia language extension. You might want to do this if:

  • You want to be work with a real value representing the sum's "tag"; or
  • You want to take advantage of the f parameter provided by DSum.


data CharacterClass a where
  Fighter :: CharacterClass Fighter
  Rogue :: CharacterClass Rogue
  Wizard :: CharacterClass Wizard

-- From the "constraints-extras" package:
$(deriveArgDict ''CharacterClass)
-- From the "dependent-sum-template" package. Not required, but useful:
$(deriveGShow ''CharacterClass)
$(deriveGEq ''CharacterClass)
$(deriveGCompare ''CharacterClass)

-- The derived `FromJSON`/`ToJSON` instances work on JSON objects like this:
-- {
--   "class": "fighter", -- or "rogue", or "wizard"
--   "data": { ... } -- the exact fields differ depending on the value at "class".
-- }
newtype Character = Character (DSum CharacterClass Identity)
  deriving (FromJSON, ToJSON)
  via (TaggedObject "Character" "class" "data" CharacterClass Identity)