Created
September 2, 2012 07:37
-
-
Save mathfur/3595636 to your computer and use it in GitHub Desktop.
json parse example about Data.Aeson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
-- need to "cabal install aeson" | |
import Data.Aeson | |
import qualified Data.Attoparsec as AP | |
import qualified Data.ByteString.Lazy.Char8 as LC | |
main = putStrLn $ LC.unpack $ encode $ forceEither $ AP.parseOnly json "{\"foo\":5}" | |
forceEither :: Show e => Either e a -> a | |
forceEither (Left x) = error (show x) | |
forceEither (Right x) = x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment