News for hackers. Stuff that matters.
Re:Haskell for Web Developers by ocharles on Friday July 26, 2013 @12:07PM (#6108922)
When it comes to encoding JSON, you don't have to represent everything. For example, you can always do:

object [ "foo" .= object [ "bar" .= [ "Yum", "Waffles!"] ] ]

Which will give you {"foo": {"bar": ["Yum", "Waffles!"]}}.

You can do traversals when decoding too:

tasty :: JSON -> Parser [String] tasty json = json .: "foo" >>= (.: "bar")

You can also do similar things with lens-aeson:

tasty json = json & key "foo" . key "bar" . _Array

Though I'm less familiar with that, and you won't be inside the Parser monad.

There are no comments on this comment yet.