TPH – Episode 1, JSON

Ready for some JSON and for some Haskell?

If so, join me in the first episode of The Pragmatic Haskeller called “JSON”

I’ve decided to do something which has been on the cards for a long time, namely using School of Haskell. So here we go, enjoy this new interactive tutorial :

Episode 1 – JSON

Stay tuned and enjoy your Haskell weekend!



This entry was posted in Jan's Blog. Bookmark the permalink.

4 Responses to TPH – Episode 1, JSON

  1. Bas van Dijk says:

    Nice tutorial!

    Some time ago I added the with* Value inspection functions to aeson. With them you can write the following:

    instance FromJSON Recipe where
    parseJSON (Object r) = Recipe
    r .: "name"
    r .: "ingredients"
    r .: "steps"
    parseJSON _ = mzero


    instance FromJSON Recipe where
    parseJSON = withObject "Recipe" $ \r -> Recipe
    r .: "name"
    r .: "ingredients"
    r .: "steps"

    which is shorter and gives better error messages.

  2. Alfredo Di Napoli says:

    Nice tip, thanks! In theory, the best option, when we don’t care about performance, would be to use the Typeable instance and let Aeson derive for us the JSON :)

  3. Bas van Dijk says:

    If you do care about performance and want the convenience of automatic JSON encoding I would recommend the GHC Generics or Template Haskell automatic derivations.

    Note that I recently added support for more encoding options in both the GHC Generics and TH code.

  4. Alfredo Di Napoli says:

    Nice, thanks!

Leave a Reply