Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HsJSON

Um mini encoder/decoder de JSON em Haskell.

Exemplo

import qualified HsJSON as JSON

rawJSON :: String
rawJSON = "{ \"status\": 200 }"

main :: IO ()
main = case JSON.decode rawJSON of
  Right json -> do
    print json               -- Obj [("status", Int 200)]
    print (JSON.encode json) -- "{\"status\":200}"
  
  Left err -> print err

Tipos

data JSON
  = Obj [(String, JSON)]  -- Objeto: {"a": b}
  | Arr [JSON]            -- Array: [a, b]
  | Str String            -- String: "a"
  | Int Int               -- Inteiro: 1
  | Dou Double            -- Float: 1.4
  | Boo Bool              -- Boolean
  | Nil                   -- Null

Código puramente recreativo e com o objetivo de aprofundar-me no aprendimento da linguagem.

About

Um mini encoder/decoder de JSON em Haskell.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages