Copyright | (c) Anton Gushcha 2016 |
---|---|
License | MIT |
Maintainer | ncrashed@gmail.com |
Stability | experimental |
Portability | Portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Common problem in REST interfaces when you need to return nothing as result,
usage of ()
will produce `[]` JSON. That causes problems in some JSON parsers
in other languages.
So, Unit
serialises into empty JSON object:
>>>
encode Unit
"{}"
Documentation
Data type that serialise into empty object in aeson
>>>
encode Unit
"{}"
>>>
encode $ toSchema (Proxy :: Proxy Unit)
"{\"type\":\"object\"}"
Also the FromJSON
instance is just `pure Unit`, so it never fails.