Skip to content

Instantly share code, notes, and snippets.

@cschneid
Created February 17, 2015 18:56
Show Gist options
  • Select an option

  • Save cschneid/68ae9623247e966488a3 to your computer and use it in GitHub Desktop.

Select an option

Save cschneid/68ae9623247e966488a3 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Aeson
import Data.ByteString.Lazy.Char8
import Data.Maybe
import Debug.Trace
import Data.Vector
import qualified Data.Text as T
rawJson = pack "[{\"type\": \"PublicationA\", \"identifier\": \"192854657\"}, {\"type\": \"PublicationB\", \"identifier\": \"10491810681\"}]"
main = do
let val = decode rawJson :: Maybe Value
print $ fromJust val
let val2 = decode rawJson :: Maybe Pub
print $ fromJust val2
-- ID For Publication A, then ID For Publication B
data Pub = Pub String String deriving Show
instance FromJSON Pub where
parseJSON (Array v) = do
a <- case v ! 0 of
(Object o) -> o .: "identifier"
b <- case v ! 1 of
(Object o) -> o .: "identifier"
return $ Pub a b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment