Nested user-defined types with Aeson

Sometimes one knows only part of the structure to be parsed out of JSON ahead of time, with some of that structure being defined by a user or consumer of the API. The solution to this in general and when using Aeson to make the wrapper type parametric.

When I decode the parameterized Status type, as long as I provide a type whose structure matches the JSON, I’ll get my data. It would look something like:

I used the Aeson generics support to generate the required FromJSON instance for Version. Aeson generics didn’t work with Status. I haven’t gotten generics or template haskell to work for parametric types. The typeclass instance was trivial anyway.

I know this site is a bit of a disaster zone, but if you like my writing or think you could learn something useful from me, please take a look at the Haskell book I've been writing. There's a free sample available too!