Skip to content

Instantly share code, notes, and snippets.

@jproyo
Created July 20, 2020 07:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jproyo/30de33a788754dbab8b1d008a81130bf to your computer and use it in GitHub Desktop.
Save jproyo/30de33a788754dbab8b1d008a81130bf to your computer and use it in GitHub Desktop.
Toy Example for decoding JSON from Stdin
{-# 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