Skip to content

Instantly share code, notes, and snippets.

@chpatrick
Created April 28, 2015 19:37
Show Gist options
  • Save chpatrick/06ec96db8fd06394aa9e to your computer and use it in GitHub Desktop.
Save chpatrick/06ec96db8fd06394aa9e to your computer and use it in GitHub Desktop.
JSON array conduit
import Conduit
import Control.Applicative
import Control.Monad
import Data.Aeson
import Data.Aeson.Parser
import Data.Attoparsec.ByteString.Char8 as AP
import qualified Data.ByteString.Char8 as BS
import Data.Conduit.Attoparsec
arrayConduit :: MonadThrow m => Conduit BS.ByteString m Value
arrayConduit = sinkParser (char '[') *> parseElem value
where
parseElem p = join $ sinkParser $
skipSpace *>
((return () <$ char ']') <|>
((\v -> yield v >> parseElems) <$> p))
parseElems = parseElem (char ',' *> skipSpace *> value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment