I have such an ugly part of code:
request <- parseUrl "someUrl.com"
res <- withManager $ httpLbs request
case decode $ responseBody res :: Maybe Aeson.Value of
Just (Aeson.Object jsonObject) ->
case (HashMap.lookup "aaa" jsonObject) of
Just a ->
case a of
Aeson.Object jsonObject2 ->
case (HashMap.lookup "bbb" jsonObject2) of
Just b ->
case b of
Aeson.Object jsonObject3 ->
case (HashMap.lookup "ccc" jsonObject3) of
Just c ->
case c of
Array d ->
case (d ! 1) of
String a -> print a
_ -> error "error!!!"
_ -> error "error!!"
_ -> error "error!!"
_ -> error "error!!"
_ -> error "error!!"
_ -> error "error!!"
_ -> error "error!!"
_ -> error "Invalid JSON"
It does work well but it doesn't look good. How do I simplify it? I'm positive there is a way to do this. Note that I'm not using any custom data type for parsing a JSON and don't want to.