@hackage generic-aeson0.2.0.14
Derivation of Aeson instances using GHC generics.
Installation
Dependencies (10)
- aeson >=0.6 && <2.3
- attoparsec >=0.11 && <0.15
- base >=4.4 && <4.22
- generic-deriving >=1.6 && <1.15
- ghc-prim
- mtl >=2.0 && <2.4 Show all…
Dependents (7)
@hackage/acme-everything, @hackage/mu-servant-server, @hackage/rest-gen, @hackage/json-schema, @hackage/rest-example, @hackage/planet-mitchell, Show all…
generic-aeson
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.
-
Maybevalues 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.