YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
17
Task/JSON/Haskell/json-3.hs
Normal file
17
Task/JSON/Haskell/json-3.hs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{-# LANGUAGE DeriveGeneric, OverloadedStrings #-}
|
||||
import Data.Aeson
|
||||
import GHC.Generics
|
||||
|
||||
data Person = Person { firstName :: String
|
||||
, lastName :: String
|
||||
, age :: Maybe Int
|
||||
} deriving (Show, Eq, Generic)
|
||||
|
||||
instance FromJSON Person
|
||||
instance ToJSON Person
|
||||
|
||||
main = do
|
||||
let test1 = "{\"firstName\":\"Bob\", \"lastName\":\"Smith\"}"
|
||||
test2 = "{\"firstName\":\"Miles\", \"lastName\":\"Davis\", \"age\": 45}"
|
||||
print (decode test1 :: Maybe Person)
|
||||
print (decode test2 :: Maybe Person)
|
||||
Loading…
Add table
Add a link
Reference in a new issue