Skip to content

Instantly share code, notes, and snippets.

@Yotamho
Last active March 30, 2021 12:24
Show Gist options
  • Select an option

  • Save Yotamho/49b3b13db8d1bf931a3aed8daff7f8a8 to your computer and use it in GitHub Desktop.

Select an option

Save Yotamho/49b3b13db8d1bf931a3aed8daff7f8a8 to your computer and use it in GitHub Desktop.
import org.typelevel.jawn._
import org.typelevel.jawn.ast.JValue
object JawnChunkParsing {
val parser = AsyncParser[JValue](AsyncParser.ValueStream)
fs2.Stream.emits(
"""
|{"adiel": "isGever", "yotam": 1111}
|{"adiel": "blahblah", "yotam": -14}
|{"adiel": "nahanaha", "yotam": 0}
|""".stripMargin).map(_.toByte)
.chunks
.flatMap(c => parser.absorb(c.toBytes.values) match {
case Right(js) => fs2.Stream.emits(js)
case Left(e) => fs2.Stream.raiseError(e)
})
parser.finish()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment