digestive-functors-aeson-1.1.12.1: Run digestive-functors forms against JSON

Safe HaskellNone
LanguageHaskell98

Text.Digestive.Aeson

Description

Run digestive-functors forms against JSON.

Synopsis

Documentation

digestJSON Source

Arguments

:: Monad m 
=> Form v m a

The form to evaluate.

-> Value

The JSON document to use for validation. If you need to use only part of this document, you need to transform this value first. You may find the aeson-lens package useful for this.

-> m (View v, Maybe a) 

Given a JSON document and a form, attempt to use the JSON document to evaluation the form. If the form fails validation, then Nothing is returned.

Example:

    import Data.Aeson (json)
    import Data.Attoparsec.Lazy (parse, maybeResult)
    import Text.Digestive.Aeson (digestJSON)
    ...
    Just parsedJson <- maybeResult . parse json <$> fetchJsonText
    digestJSON "" myForm parsedJson

jsonErrors :: ToJSON a => View a -> Value Source

Takes a View and displays any errors in a hierachical format that matches the expected input.

Example:

    > jsonErrors myForm
    {"person":{"name":"This field is required"}}