Add 'parseJsonBody' to Yesod.Json.

This commit is contained in:
Felipe Lessa 2011-12-26 10:45:11 -02:00
parent 3e6235a8ac
commit 9da7d0a1fd
2 changed files with 21 additions and 8 deletions

View File

@ -5,6 +5,8 @@ module Yesod.Json
( -- * Convert from a JSON value ( -- * Convert from a JSON value
defaultLayoutJson defaultLayoutJson
, jsonToRepJson , jsonToRepJson
-- * Convert to a JSON value
, parseJsonBody
-- * Compatibility wrapper for old API -- * Compatibility wrapper for old API
, Json , Json
, jsonScalar , jsonScalar
@ -22,8 +24,10 @@ import Yesod.Widget (GWidget)
import qualified Data.Aeson as J import qualified Data.Aeson as J
import qualified Data.Aeson.Encode as JE import qualified Data.Aeson.Encode as JE
import Data.Aeson.Encode (fromValue) import Data.Aeson.Encode (fromValue)
import Data.Attoparsec.Enumerator (iterParser)
import Data.Text (pack) import Data.Text (pack)
import Control.Arrow (first) import Control.Arrow (first)
import Control.Monad.Trans.Class (lift)
#if MIN_VERSION_aeson(0, 4, 0) #if MIN_VERSION_aeson(0, 4, 0)
import Data.HashMap.Strict (fromList) import Data.HashMap.Strict (fromList)
#else #else
@ -62,6 +66,13 @@ defaultLayoutJson w json = do
jsonToRepJson :: J.Value -> GHandler sub master RepJson jsonToRepJson :: J.Value -> GHandler sub master RepJson
jsonToRepJson = return . RepJson . toContent jsonToRepJson = return . RepJson . toContent
-- | Parse the request body as a JSON value.
--
-- /Since: 0.2.3/
parseJsonBody :: GHandler sub master J.Value
parseJsonBody = lift $ iterParser J.json'
type Json = J.Value type Json = J.Value
jsonScalar :: String -> Json jsonScalar :: String -> Json

View File

@ -1,5 +1,5 @@
name: yesod-json name: yesod-json
version: 0.2.2.3 version: 0.2.3
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -13,15 +13,17 @@ homepage: http://www.yesodweb.com/
description: Generate content for Yesod using the aeson package. description: Generate content for Yesod using the aeson package.
library library
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod-core >= 0.9 && < 0.10 , yesod-core >= 0.9 && < 0.10
, aeson >= 0.3 , aeson >= 0.3
, text >= 0.8 && < 0.12 , text >= 0.8 && < 0.12
, shakespeare-js >= 0.10 && < 0.11 , shakespeare-js >= 0.10 && < 0.11
, vector >= 0.9 , vector >= 0.9
, containers >= 0.2 && < 0.5 , containers >= 0.2 && < 0.5
, unordered-containers , unordered-containers
, blaze-builder , blaze-builder
, attoparsec-enumerator >= 0.3 && < 0.4
, transformers >= 0.2.2 && < 0.3
exposed-modules: Yesod.Json exposed-modules: Yesod.Json
ghc-options: -Wall ghc-options: -Wall