yesod-json- Generate content for Yesod using the aeson package.

Safe HaskellSafe-Infered




Convert from a JSON value



:: (Yesod master, ToJSON a) 
=> GWidget sub master ()


-> a


-> GHandler sub master RepHtmlJson 

Provide both an HTML and JSON representation for a piece of data, using the default layout for the HTML output (defaultLayout).

Since: 0.3.0

jsonToRepJson :: ToJSON a => a -> GHandler sub master RepJsonSource

Wraps a data type in a RepJson. The data type must support conversion to JSON via ToJSON.

Since: 0.3.0

Convert to a JSON value

parseJsonBody :: FromJSON a => GHandler sub master (Result a)Source

Parse the request body to a data type as a JSON value. The data type must support conversion from JSON via FromJSON. If you want the raw JSON value, just ask for a Result Value.

Since: 0.3.0

parseJsonBody_ :: FromJSON a => GHandler sub master aSource

Same as parseJsonBody, but return an invalid args response on a parse error.

Produce JSON values

data Value

A JSON value represented as a Haskell value.

object :: ToJSON a => [(Text, a)] -> ValueSource

Convert a list of pairs to an Object.

array :: ToJSON a => [a] -> ValueSource

Convert a list of values to an Array.

(.=) :: ToJSON a => Text -> a -> Pair

Construct a Pair from a key and a value.

Convenience functions



:: (Yesod master, ToJSON a) 
=> Route master

Redirect target

-> a

Data to send via JSON

-> GHandler sub master RepJson 

jsonOrRedirect simplifies the scenario where a POST handler sends a different response based on Accept headers:

  1. 200 with JSON data if the client prefers application/json (e.g. AJAX).
  2. 3xx otherwise, following the PRG pattern.