Last active
June 18, 2016 21:07
-
-
Save tippenein/328499a943d1b60b324705ceeddce2cc to your computer and use it in GitHub Desktop.
json encoding example
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
#!/usr/bin/env runhaskell | |
{-# LANGUAGE DeriveAnyClass #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Data.Aeson as Aeson | |
import Data.Text | |
import Data.Time.Clock | |
import GHC.Generics | |
data UserEvent = UserEvent | |
{ uuid :: Text | |
, eventName :: Text | |
, timestamp :: UTCTime | |
} deriving (Show, Eq, Generic, Aeson.ToJSON, Aeson.FromJSON) | |
main = do | |
now <- getCurrentTime | |
let ue = UserEvent "123-sadf-34" "whatever" now | |
print (Aeson.encode ue) | |
-- stack runghc encoding.hs | |
-- "{\"uuid\":\"123-sadf-34\",\"eventName\":\"whatever\",\"timestamp\":\"2016-06-18T21:06:57.184643000000Z\"}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment