I would like to parse the values of a json object to a list.
Here's my current approach (simplified and the newtype is based on the results of: Aeson: derive some (but not all) fields of a struct (means I need it)):
Json:
{"v1": 1, "v2": 2}
Wanted result:
Test [1,2]
Current approach:
import Data.Aeson
import Data.HashMap.Strict (elems)
newtype Test = Test [Int]
instance FromJSON Test where
parseJSON (Object o) =
mapM parseJSON (elems o)
Compilation error:
• Couldn't match type ‘[b0]’ with ‘Test’
Expected type: aeson-1.1.2.0:Data.Aeson.Types.Internal.Parser Test
Actual type: aeson-1.1.2.0:Data.Aeson.Types.Internal.Parser [b0]
• In the expression: mapM parseJSON (elems o)