Skip to content

Instantly share code, notes, and snippets.

@mlopes
Created October 20, 2017 16:44
Show Gist options
  • Save mlopes/a79a50ca2355cc21998d0f0c075c0b50 to your computer and use it in GitHub Desktop.
Save mlopes/a79a50ca2355cc21998d0f0c075c0b50 to your computer and use it in GitHub Desktop.
import Data.Text (Text)
import qualified Data.Yaml as Y
import Data.Yaml (FromJSON(..), (.:))
import Data.ByteString (ByteString)
import Text.RawString.QQ
import Control.Applicative
actionsYml :: ByteString
actionsYml = [r|
action:
- description: some description
- project: inbox
- contexts: [ online, computer ]
|]
data Action =
Action {
description :: Text
, project :: Text
, contexts :: [Text]
} deriving (Eq, Show)
instance FromJSON Action where
parseJSON (Y.Object v) =
Action <$>
v .: "description" <*>
v .: "project" <*>
v .: "contexts"
parseJSON _ = fail "Expected Object for Action value"
data Actions =
Actions {
action :: [Action]
} deriving (Eq, Show)
instance FromJSON Actions where
parseJSON (Y.Object v) =
Actions <$>
v .: "action"
parseJSON _ = fail "Expected Object for Actions value"
main :: IO ()
main =
print $ (Y.decode actionsYml :: Maybe(Actions))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment