-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Generate content for Yesod using the aeson package.
--   
--   Generate content for Yesod using the aeson package.
@package yesod-json
@version 1.1.2.2

module Yesod.Json

-- | Provide both an HTML and JSON representation for a piece of data,
--   using the default layout for the HTML output (<a>defaultLayout</a>).
--   
--   <i>Since: 0.3.0</i>
defaultLayoutJson :: (Yesod master, ToJSON a) => GWidget sub master () -> a -> GHandler sub master RepHtmlJson

-- | Wraps a data type in a <a>RepJson</a>. The data type must support
--   conversion to JSON via <a>ToJSON</a>.
--   
--   <i>Since: 0.3.0</i>
jsonToRepJson :: ToJSON a => a -> GHandler sub master RepJson

-- | Parse the request body to a data type as a JSON value. The data type
--   must support conversion from JSON via <a>FromJSON</a>. If you want the
--   raw JSON value, just ask for a <tt><a>Result</a> <a>Value</a></tt>.
--   
--   <i>Since: 0.3.0</i>
parseJsonBody :: FromJSON a => GHandler sub master (Result a)

-- | Same as <a>parseJsonBody</a>, but return an invalid args response on a
--   parse error.
parseJsonBody_ :: FromJSON a => GHandler sub master a

-- | A JSON value represented as a Haskell value.
data Value :: *
Object :: !Object -> Value
Array :: !Array -> Value
String :: !Text -> Value
Number :: !Number -> Value
Bool :: !Bool -> Value
Null :: Value

-- | Convert a list of pairs to an <a>Object</a>.
object :: ToJSON a => [(Text, a)] -> Value

-- | Convert a list of values to an <a>Array</a>.
array :: ToJSON a => [a] -> Value

-- | Construct a <a>Pair</a> from a key and a value.
(.=) :: ToJSON a => Text -> a -> Pair

-- | jsonOrRedirect simplifies the scenario where a POST handler sends a
--   different response based on Accept headers:
--   
--   <ol>
--   <li>200 with JSON data if the client prefers <tt>application/json</tt>
--   (e.g. AJAX, see <tt>acceptsJSON</tt>).</li>
--   <li>3xx otherwise, following the PRG pattern.</li>
--   </ol>
jsonOrRedirect :: (Yesod master, ToJSON a) => Route master -> a -> GHandler sub master RepJson

-- | Returns <tt>True</tt> if the client prefers <tt>application/json</tt>
--   as indicated by the <tt>Accept</tt> HTTP header.
acceptsJson :: Yesod master => GHandler sub master Bool
