Skip to content

Instantly share code, notes, and snippets.

@mathfur
Created September 2, 2012 07:37
Show Gist options
  • Save mathfur/3595636 to your computer and use it in GitHub Desktop.
Save mathfur/3595636 to your computer and use it in GitHub Desktop.
json parse example about Data.Aeson
{-# 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