When trying to parse some simple JSON using Aeson I get a type error I don't understand. I have the following JSON
jsonString = "[\"a\", [\"b\", \"c\"]]" :: L.ByteString
and I have defined the following imports and code:
import Data.Aeson
import GHC.Generics
import qualified Data.ByteString.Lazy as L
data Ch = Ch {
c1 :: String,
c2 :: (String, String)
} deriving (Show, Generic)
instance FromJSON Ch
When I try to use eitherDecode
on this string with my Ch
type I get an error
*Aeson> eitherDecode jsonString :: Either String Ch
Left "Error in $: expected record (:*:), encountered Array"
Can someone explain me the error and tell me how I should parse this JSON?
An approach that would work is
eitherDecode jsonString :: Either String (String, (String, String))
but I'd rather go to my type directly.