The problem is this line:
putStrLn value
Since the type of putStrLn
is String -> IO ()
, the type of value
is inferred as String
, so the FromJSON
instance for strings will be used, which will only decode strings, since that's what the type can handle. To decode something else, you need a different type for value
.
Try
print (value :: JSON.Object)
if you expect an object, or
print (value :: JSON.Value)
if any JSON value is acceptable.
Note the use of print
instead of putStrLn
. print
accepts any type with a Show
instance, so unlike putStrLn
it does not force its argument to be a string. Also note that print value
without the type annotation would not work in this example, as there would not be enough information for the compiler to deduce which type value
should have, and therefore which Show
and FromJSON
instances to use.