Created
April 28, 2015 19:37
-
-
Save chpatrick/06ec96db8fd06394aa9e to your computer and use it in GitHub Desktop.
JSON array conduit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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