Why reinvent the wheel? There is a semi-standard representation for what you call Date
in the time
package - it is called Day
. It gets better: not only does that same package even give you the utilities for parsing Day
from the format you have, those utilities are even exported to aeson
. Yep, there are already ToJSON
and FromJSON
instances in aeson
for Day
:
ghci> :set -XOverloadedStrings
ghci> import Data.Time.Calendar
ghci> import Data.Aeson
ghci> fromJSON "2015-04-12" :: Result Day
Success 2015-04-12
ghci> toJSON (fromGregorian 2015 4 12)
String "2015-04-12"
If you really want to extract the days, months, and years, you can always use toGregorian :: Day -> (Integer, Int, Int)
. Sticking to the standard abstraction is probably a good long-term choice though.