For this example programm using Aeson:
module Main where
import Data.Maybe
import Data.Aeson
import Data.Map as Map
import Data.Functor
import qualified Data.ByteString.Lazy as LBS
main = do
jsonContent <- LBS.readFile "templates/test.json"
print (decode jsonContent :: Maybe TemplateConfig)
newtype TemplateConfig = TemplateConfig (Map String String)
deriving Show
instance FromJSON TemplateConfig where
parseJSON val = TemplateConfig <$> parseJSON val
i get an error complaining about a missing instance:
$ ghc test.hs
[1 of 1] Compiling Main ( test.hs, test.o )
test.hs:17:45:
No instance for (FromJSON (Map String String))
arising from a use of `parseJSON'
Possible fix:
add an instance declaration for (FromJSON (Map String String))
In the second argument of `(<$>)', namely `parseJSON val'
In the expression: TemplateConfig <$> parseJSON val
In an equation for `parseJSON':
parseJSON val = TemplateConfig <$> parseJSON val
I understand I need a FromJSON instance to parse JSON and there are also a lot of commonly used instances included in Aeson. According to the documentation there is an instance FromJSON v => FromJSON (Map String v)
and I thought it should get used in this case.
What am I missing?