Idris2Doc : Language.JSON.Interfaces

Language.JSON.Interfaces

(source)
Interfaces for converting values from/to JSON.

(C) The Idris Community, 2021

Definitions

interface ToJSON : Type -> Type
  A 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)]
```

Parameters: a
Methods:
toJSON : a -> JSON

Implementations:
ToJSON JSON
ToJSON Integer
ToJSON Int
ToJSON Bits8
ToJSON Bits16
ToJSON Bits32
ToJSON Bits64
ToJSON Double
ToJSON Nat
ToJSON String
ToJSON Char
ToJSON Bool
ToJSON 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 -> JSON
Totality: total
Visibility: public export
interface FromJSON : Type -> Type
  A 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
```

Parameters: a
Methods:
fromJSON : JSON -> Maybe a

Implementations:
FromJSON JSON
FromJSON Integer
FromJSON Int
FromJSON Bits8
FromJSON Bits16
FromJSON Bits32
FromJSON Bits64
FromJSON Double
FromJSON Nat
FromJSON String
FromJSON Char
FromJSON Bool
FromJSON 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
Totality: total
Visibility: public export