I have the below code for parsing Int from an object. But unable to find the correct import for Key
.
parseInt :: Object -> Key -> Parser Int
parseInt v field =
asum
[ v .: field,
do
s <- v .: field
case readMaybe s :: Maybe Int of
Nothing -> fail "not a number"
Just x -> return x
]
I have tried
import Data.Aeson
and
import Data.Aeson.Types
But get the error
Not in scope: type constructor or class ‘Key’
A data constructor of that name is in scope; did you mean DataKinds?
What should be the correct import for Key
in my function?
It looks like you're writing code targeting aeson
2.x, but that you have aeson
1.x installed. Either upgrade (recommended), or use Text
in place of Key
there.