Skip to content

scrive/tagged-json

Repository files navigation

tagged-json

tagged-json helps you derive aeson and openapi3 instances with a flat, explicitly-tagged JSON representation.

It is built around DerivingVia and one exported module: Deriving.TaggedJson.

What it provides

  • Deriving via GTaggedJSON for:
    • ToJSON
    • FromJSON
    • ToSchema
    • ToKeyMap (helper class used by the generic JSON encoder)
  • Flat object encoding (no extra wrapper nesting for constructors/newtypes)
  • Explicit sum tags (tagKey) for unambiguous sum decoding
  • Configurable field/constructor/datatype name modifiers
  • Optional omission of Nothing fields during encoding
  • Schema customization via SchemaDetails

Development

To run the tests, run:

cabal test

Formatting:

fourmolu -i .
cabal-fmt -i tagged-json.cabal

Linting:

hlint -j .

Usage example

See the runnable example in:

Run the example with:

cabal run tagged-json-example

Notes

  • If a datatype has multiple constructors, tagKey must be set.
  • If two types with the same name co-exist in the same OpenApi schema, their definitions will conflict.

About

Derive JSON representation and OpenAPI specs for Haskell data types

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors