Interfaces for converting values from/to JSON. (C) The Idris Community, 2021
interface ToJSON : Type -> TypeA type that can be converted to JSON.
An example type and implementation is:
```idris example
record Position where
constructor MkPosition
x : Integer
y : Integer
ToJSON Position where
toJSON pos = JObject [("x", toJSON pos.x), ("y", toJSON pos.y)]
```
toJSON : a -> JSONToJSON JSONToJSON IntegerToJSON IntToJSON Bits8ToJSON Bits16ToJSON Bits32ToJSON Bits64ToJSON DoubleToJSON NatToJSON StringToJSON CharToJSON BoolToJSON a => ToJSON (Maybe a)ToJSON a => ToJSON (List a)ToJSON ()(ToJSON a, ToJSON b) => ToJSON (a, b)ToJSON v => ToJSON (SortedMap String v)ToJSON a => ToJSON (Inf a)toJSON : ToJSON a => a -> JSONinterface FromJSON : Type -> TypeA type that can be possibly converted from JSON.
An example type and implementation is:
```idris example
record Position where
constructor MkPosition
x : Integer
y : Integer
FromJSON Position where
fromJSON (JObject arg) = do
x <- lookup "x" arg >>= fromJSON
y <- lookup "y" arg >>= fromJSON
pure $ MkPosition x y
fromJSON _ = neutral
```
fromJSON : JSON -> Maybe aFromJSON JSONFromJSON IntegerFromJSON IntFromJSON Bits8FromJSON Bits16FromJSON Bits32FromJSON Bits64FromJSON DoubleFromJSON NatFromJSON StringFromJSON CharFromJSON BoolFromJSON a => FromJSON (Maybe a)FromJSON a => FromJSON (List a)FromJSON ()(FromJSON a, FromJSON b) => FromJSON (a, b)FromJSON v => FromJSON (SortedMap String v)FromJSON a => FromJSON (Inf a)fromJSON : FromJSON a => JSON -> Maybe a