The problem is that decode
expects a ByteString
and you are passing a String
.
Try this in ghci
:
:m +Data.ByteString.Lazy.Char8
decode $ pack "{\"name\":\"Joe\",\"age\":12}" :: Maybe Person
In real code you shouldn't use the Char8
module as it just truncates Char
s to 8 bits without taking any account of encoding. Generally you should aim to start out with a ByteString
, e.g. by reading it from disk using the functions in Data.ByteString.Lazy
.