Created
July 20, 2020 07:10
-
-
Save jproyo/30de33a788754dbab8b1d008a81130bf to your computer and use it in GitHub Desktop.
Toy Example for decoding JSON from Stdin
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 TypeApplications #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Test where | |
import Data.Aeson | |
import Data.ByteString.Lazy as BL | |
import Data.Text as T | |
data User = User { name :: Text | |
, surname :: Text | |
} deriving Show | |
instance FromJSON User where | |
parseJSON = | |
withObject "user" $ \obj -> User <$> (obj .: "name") <*> (obj .: "surname") | |
main :: IO () | |
main = BL.getContents >>= print . decode' @User |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment