I have no experience at Haskell. I am trying to parse many files .jsonin a data structure in Haskell using aeson . However, for reasons beyond my control, I need to save the name of the file from which the data was analyzed as one of the fields in my data. A simple example of what I have so far:
data Observation = Observation { id :: Integer
, value :: Integer
, filename :: String}
instance FromJSON Observation where
parseJson (Object v) =
Observation <$> (read <$> v .: "id")
<*> v .: "value"
<*> ????
My question is: what is a smart way to serialize my data when parsing a json file with access to the file name?
What comes to my mind - is to identify one datalike NotNamedObservation, initialize it, and then have a function that converts NotNamedObservation -> String -> Observation(where String - the file name), but it sounds very bad. p>
Thank.