yesod- Creation of type-safe, RESTful web applications.




Efficient generation of JSON documents.



data Json Source

A monad for generating Json output. It wraps the Builder monoid from the blaze-builder package.

This is an opaque type to avoid any possible insertion of non-JSON content. Due to the limited nature of the JSON format, you can create any valid JSON document you wish using only jsonScalar, jsonList and jsonMap.


jsonToContent :: Json -> GHandler sub master ContentSource

Extract the final result from the given Json value.

See also: applyLayoutJson in Yesod.Yesod.

jsonToRepJson :: Json -> GHandler sub master RepJsonSource

Wraps the Content generated by jsonToContent in a RepJson.

Generate Json output

jsonScalar :: String -> JsonSource

Outputs a single scalar. This function essentially:

  • Performs JSON encoding.
  • Wraps the resulting string in quotes.

jsonList :: [Json] -> JsonSource

Outputs a JSON list, eg ["foo","bar","baz"].

jsonMap :: [(String, Json)] -> JsonSource

Outputs a JSON map, eg {"foo":"bar","baz":"bin"}.

jsonRaw :: ByteString -> JsonSource

Outputs raw JSON data without performing any escaping. Use with caution: this is the only function in this module that allows you to create broken JSON documents.