[Haskell-beginners] Reading JSON using Text.JSON

Christopher Done chrisdone at googlemail.com
Mon May 16 01:38:02 CEST 2011


On 15 May 2011 23:20, Magnus Therning <magnus at therning.org> wrote:

> I wrote down some stuff from my first look at json, maybe it can
> help you in getting further?
>
> http://therning.org/magnus/archives/719


FWIW, rather than:

readJSON (JSObject obj) = let
        jsonObjAssoc = fromJSObject obj
    in do
        para <- mLookup "para" jsonObjAssoc >>= readJSON
        seeAlso <- mLookup "GlossSeeAlso" jsonObjAssoc >>= readJSON
        return $ GlossDef
            { glossDefPara = para
            , glossDefSeeAlso = seeAlso
            }

You can just write:

readJSON object = do obj <- readJSON object
                     GlossDef <$> valFromObj "para" obj
                              <*> valFromObj "GlossSeeAlso" obj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110516/e17f6706/attachment.htm>


More information about the Beginners mailing list