Skip to content

Instantly share code, notes, and snippets.

@nakaji-dayo
Last active August 29, 2015 14:07
Show Gist options
  • Save nakaji-dayo/d035912adad6911a8b36 to your computer and use it in GitHub Desktop.
Save nakaji-dayo/d035912adad6911a8b36 to your computer and use it in GitHub Desktop.
rr = case decode "[{\"key\":\"yahoo\", \"count\": 5},{\"key\":\"google\"}]" of
Nothing -> fail "decode error"
Just v -> (parse parser v) :: Result String
where parser = parseJSON >=> withArray "array" (.!! 0) >=> withObject "object" (.: "key")
(.!!) :: (FromJSON a) => Array -> Int -> Parser a
arr .!! i
| V.length arr >= i = parseJSON $ arr V.! i
| otherwise = fail "hogeeee"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment