Skip to content

Instantly share code, notes, and snippets.

@YoEight
Created March 4, 2014 08:11
Show Gist options
  • Select an option

  • Save YoEight/9342231 to your computer and use it in GitHub Desktop.

Select an option

Save YoEight/9342231 to your computer and use it in GitHub Desktop.
Aeson parsing and Snap
import Data.Traversable (for)
import Data.Aeson (Value, json)
import Data.AttoParsec (parseOnly)
import Snap.Core
getPostJsonParam :: MonadSnap m => ByteString -> m (Maybe Value)
getPostJsonParam key = do
bsOpt <- getPostParam key
for bsOpt $ \bs ->
case parseOnly json bs of
Left e -> fail e -- Of course, use a better way to handle that kind of error
Right v -> return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment