Descriptive.JSON

descriptive-0.9.4: Self-describing consumers/parsers; forms, cmd-line args, JSON, etc.

Safe Haskell | None
Language | Haskell98

Descriptive.JSON

Contents

- Consumers
- Annotations
- Description

Description

A JSON API which describes itself.

Synopsis

- parse :: Monad m => d -> (a -> StateT s m (Maybe b)) -> Consumer s d m a -> Consumer s d m b
- object :: Monad m => Text -> Consumer Object (Doc d) m a -> Consumer Value (Doc d) m a
- key :: Monad m => Text -> Consumer Value (Doc d) m a -> Consumer Object (Doc d) m a
- keyMaybe :: Monad m => Text -> Consumer Value (Doc d) m a -> Consumer Object (Doc d) m (Maybe a)
- array :: Monad m => Text -> Consumer Value (Doc d) m a -> Consumer Value (Doc d) m (Vector a)
- string :: Monad m => Text -> Consumer Value (Doc d) m Text
- integer :: Monad m => Text -> Consumer Value (Doc d) m Integer
- double :: Monad m => Text -> Consumer Value (Doc d) m Double
- bool :: Monad m => Text -> Consumer Value (Doc d) m Bool
- null :: Monad m => Text -> Consumer Value (Doc d) m ()
- label :: Monad m => d -> Consumer s (Doc d) m a -> Consumer s (Doc d) m a
- data Doc a
  - = Integer !Text
  - | Double !Text
  - | Text !Text
  - | Boolean !Text
  - | Null !Text
  - | Object !Text
  - | Key !Text
  - | Array !Text
  - | Label !a

# Consumers

parse

Arguments

:: Monad m |
=> d | Description of what it expects.
-> (a -> StateT s m (Maybe b)) | Attempt to parse the value.
-> Consumer s d m a | Consumer to add validation to.
-> Consumer s d m b | A new validating consumer.

Parse from a consumer.

object

Arguments

:: Monad m |
=> Text | Description of what the object is.
-> Consumer Object (Doc d) m a | An object consumer.
-> Consumer Value (Doc d) m a |

Consume an object.

key

Arguments

:: Monad m |
=> Text | The key to lookup.
-> Consumer Value (Doc d) m a | A value consumer of the object at the key.
-> Consumer Object (Doc d) m a |

Consume from object at the given key.

keyMaybe

Arguments

:: Monad m |
=> Text | The key to lookup.
-> Consumer Value (Doc d) m a | A value consumer of the object at the key.
-> Consumer Object (Doc d) m (Maybe a) |

Optionally consume from object at the given key, only if it exists.

array

Arguments

:: Monad m |
=> Text | Description of this array.
-> Consumer Value (Doc d) m a | Consumer for each element in the array.
-> Consumer Value (Doc d) m (Vector a) |

Consume an array.

string

Arguments

:: Monad m |
=> Text | Description of what the string is for.
-> Consumer Value (Doc d) m Text |

Consume a string.

integer

Arguments

:: Monad m |
=> Text | Description of what the integer is for.
-> Consumer Value (Doc d) m Integer |

Consume an integer.

double

Arguments

:: Monad m |
=> Text | Description of what the double is for.
-> Consumer Value (Doc d) m Double |

Consume an double.

bool

Arguments

:: Monad m |
=> Text | Description of what the bool is for.
-> Consumer Value (Doc d) m Bool |

Parse a boolean.

null

Arguments

:: Monad m |
=> Text | What the null is for.
-> Consumer Value (Doc d) m () |

Expect null.

# Annotations

label

Arguments

:: Monad m |
=> d | Some label.
-> Consumer s (Doc d) m a | A value consumer.
-> Consumer s (Doc d) m a |

Wrap a consumer with a label e.g. a type tag.

# Description

data Doc a

Description of parseable things.

Constructors

Integer !Text |
Double !Text |
Text !Text |
Boolean !Text |
Null !Text |
Object !Text |
Key !Text |
Array !Text |
Label !a |

Instances

Eq a => Eq (Doc a) |
Data a => Data (Doc a) |
Show a => Show (Doc a) |