Created
February 17, 2015 18:56
-
-
Save cschneid/68ae9623247e966488a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 #-} | |
| 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