YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
14
Task/JSON/Crystal/json-1.crystal
Normal file
14
Task/JSON/Crystal/json-1.crystal
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require "json"
|
||||
|
||||
class Foo
|
||||
JSON.mapping(
|
||||
num: Int64,
|
||||
array: Array(String),
|
||||
)
|
||||
end
|
||||
|
||||
def json
|
||||
foo = Foo.from_json(%({"num": 1, "array": ["a", "b"]}))
|
||||
puts("#{foo.num} #{foo.array}")
|
||||
puts(foo.to_json)
|
||||
end
|
||||
2
Task/JSON/Crystal/json-2.crystal
Normal file
2
Task/JSON/Crystal/json-2.crystal
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
1 ["a", "b"]
|
||||
{"num":1,"array":["a","b"]}
|
||||
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