generic-aeson

Derivation of Aeson instances using GHC generics.

Version on this page:0.2.0.9@rev:4
LTS Haskell 20.26:0.2.0.14
Stackage Nightly 2022-11-17:0.2.0.14
Latest on Hackage:0.2.0.14

See all snapshots generic-aeson appears in

BSD-3-Clause licensed by Silk
Maintained by [email protected]
This version can be pinned in stack with:generic-aeson-0.2.0.9@sha256:edcbd726cf3ea3a23e2284ac30f4b8d10fcf89acd906da4f4518dab41d175554,1144

Module documentation for 0.2.0.9

generic-aeson

Build Status

The structure of the generated JSON is meant to be close to idiomatic JSON. This means:

  • Enumerations (data types containing constructors without fields) are converted to JSON strings.

  • Record fields become JSON keys.

  • Data types with one unlabeled field convert to just that field.

  • Data types with multiple unlabeled fields become arrays.

  • Multiple constructors are represented by keys.

  • Maybe values are either an absent key, or the value.

  • Leading and trailing underscores are removed from constructor names and record fields

See tests/Main.hs in json-schema for more examples.

How does generic-aeson compare to the TH/Generics already present in aeson?

generic-aeson contains more special cases for creating more concise and idiomatic json. If you’re working with the JSON representation directly generic-aeson should feel more natural.

Will the generated format ever change?

Changing the format would incur a breaking change to every API that uses generic-aeson so we must keep it intact.

If we find a bug where the fix changes the format we need to create a new package or version the generation code.

Schemas

json-schema has generic derivation of schemas that match the generic-aeson format.

Changes

Changelog

0.2.0.9

  • Allow aeson 1.2.*
  • Fix a documentation typo

0.2.0.8

  • Fix compilation on GHC 8.

0.2.0.7

  • Allow generic-deriving 1.8.*
  • Allow vector 0.11.*

0.2.0.6

  • Allow aeson 0.9.*

0.2.0.5

  • Allow attoparsec 0.13.*

0.2.0.4

  • Fix compilation on GHC 7.4

0.2.0.3

  • Allow tagged 0.8.*

0.2.0.2

  • Allow generic-deriving 1.7.*

0.2.0.1

  • Allow text 1.2.*

0.2.0.0

  • Add gtoJsonWithSettings and gparseJsonWithSettings to customize the generated JSON, currently only to strip specified prefixes from record fields.
  • Format Change: The behavior of Maybes was inconsistent and buggy, now we always map Just directly to the value, and Nothing to null if on the top level or in an unnamed field and remove the property if it’s in a named field.
  • Changed the type of selNameT to return a Maybe Text which will be Nothing instead of "" (unnamed fields)

0.1.1.1

  • Fix regression in implementation of multipleConstructors introduced in 0.1.1

0.1.1

  • Add Generics.Generic.Aeson.Util module with helper function for interoperating packages

0.1.0.3

  • Allow attoparsec 0.12.*

0.1.0.2

  • Allow mtl 2.2.*