I'm trying to get used to some haskell libraries by solving some online practice problems.
I have some code which outputs this
Object (fromList [("ABC", String "123")])
It may also be
Object (fromList [("123", String "ABC")])
Object (fromList [(String "123", String "ABC")])
Object (fromList [("123", "ABC")])
what I need to extract is "123"
using .:
which has type (.:) :: FromJSON a => Object -> Text -> Parser a
to extract value given key raises this error
• Couldn't match type ‘Value’ with ‘HashMap Text Value’
Expected type: Object
Actual type: Value
My best guess is that I'm going to have to write a parser, but I have no idea how to go about doing that or what to look for.
Code that produced the error :
x <- (eitherDecode <$> simpleHttp url) :: IO (Either String DataSet)
case x of
Left er -> print er
Right an -> do
let l = S.toList (data1 an)
print $ l .: "ABC"
where DataSet is defined like this
newtype DataSet = DataSet {
data1 :: Object
} deriving (Show, Generic)
If I were to replace
print $ (Data.List.head l) .: "ABC"
with just
print $ (Data.List.head l)
I get
Object (fromList [("ABC", String "123")])