/circe-fs2

Streaming JSON parsing and decoding with fs2

Primary LanguageScala

circe-fs2

Build status Coverage status Gitter Maven Central

This project provides support for using fs2 for streaming JSON parsing and decoding with circe, a Scala library for encoding and decoding JSON to Scala types.

Parsing

Circe-fs2 provides three pipes to parse your streams of JSONs:

stringParser: Stream[F[_], String] => Stream[F[_], Json]

stringParser converts a stream of String to a stream of Json, Circe's representation of JSONs:

import io.circe.fs2._

val stringStream: Stream[Task, String] = ...

val parsedStream: Stream[Task, Json] = stringStream.through(stringParser)

byteParser: Stream[F[_], Byte] => Stream[F[_], Json]

byteParser converts a stream of Byte to a stream of Json:

val byteStream: Stream[Task, Byte] = ...

val parsedStream: Stream[Task, Json] = byteStream.through(byteParser)

byteParserC: Stream[F[_], Chunk[Byte]] => Stream[F[_], Json]

byteParserC converts a chunked stream of Byte to a stream of Json:

val chunkedByteStream: Stream[Task, Chunk[Byte]] = ...

val parsedStream: Stream[Task, Json] = chunkedByteStream.through(byteParserC)

Decoding

Circe-fs2 also comes with a decoder pipe which, given a Decoder[A], produces a Stream[F[_], Json] => Stream[F[_], A] pipe.

For example, using Circe's fully automatic derivation:

import io.circe.generic.auto._

case class Foo(a: Int, b: String)

val parsedStream: Stream[Task, Json] = ...

val decodedStream: Stream[Task, Foo] = parsedStream.through(decoder[Task, Foo])

Contributors and participation

All circe projects support the Typelevel code of conduct and we want all of their channels (Gitter, GitHub, etc.) to be welcoming environments for everyone.

Please see the circe contributors' guide for details on how to submit a pull request.

License

circe-fs2 is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.