I have this data structure to take the result from a JSON in Haskell, with aeson
From this URL: http://fipeapi.appspot.com/api/1/carros/marcas.json
data Marca =
Marca { keyM :: String
, idM :: Int
, fipe_nameM :: String
, nameM :: String
} deriving Show
instance FromJSON Marca where
parseJSON (Object m) =
Marca <$> m .: "key"
<*> m .: "id"
<*> m .: "fipe_name"
<*> m .: "name"
parseJSON _= mzero
This is working fine and i stored the result in a list of "Marca" named "ps"
main :: IO ()
main = do
d <- (eitherDecode <$> getJSON) :: IO (Either String [Marca])
case d of
Left err -> putStrLn err
Right ps -> print ps
return();
Now i have to create a list of Int from this "ps" with all "idM" from each "Marca", but i don't know how to do this, i try some things like:
Right ps -> let newlist = [idM x | x <- ps]
Right ps -> let newlist = [idM x | x <- [Marca]]
or
Right ps -> let newlist = map (idM x) ps
Right ps -> let newlist = map (idM x) [Marca]
But it did not work.