I would not use read because it can fail. How about:
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Aeson as Aeson
import Data.Text.Lazy (Text, fromStrict)
toCountry :: Text -> Maybe Country
toCountry text =
case text of
"United States" ->
Just USA
"Mexico" ->
Just MEXICO
_ ->
Nothing
and/or with Aeson:
instance Aeson.FromJSON Country where
parseJSON (Aeson.String s) =
maybe mempty return (toCountry (fromStrict s))
parseJSON _ = mempty
(I’m very new to haskell, so I could be totally wrong about this)