Can't find a good example. Appreciate any help. The JSON is as follows:
[{
"EXIF:Make": "Canon",
"EXIF:Model": "Canon PowerShot S95",
"EXIF:Orientation": "Horizontal (normal)",
"EXIF:XResolution": 180,
"EXIF:YResolution": 180,
"EXIF:ResolutionUnit": "inches"
}]
The code I used is as follows:
import Data.Aeson
import Data.Attoparsec
import Data.ByteString
x <- fmap (parse json) (Data.ByteString.readFile "json.txt")
How do I define & use the FromJSON
type to convert from x
into:
data Exif = Exif [[(String, String)]]
or similar data structure? Note the [[]]
-- I'm expecting the JSON to have multiple top-level entries.
Here's an idiomatic solution:
Testing:
Alternatively, here's a slightly more ugly solution that gives you the data type you requested (
[[(Text,Text)]]
).