Giter Site home page Giter Site logo

circe-fs2's Introduction

circe-fs2

Build 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 different pipes to parse your streams of JSONs depending on whether your stream is:

  • a \n-separated stream of JSON values or value stream:
{ "repo": "circe-fs2", "stars": 14 }
{ "repo": "circe-config", "stars": 5 }
  • or a JSON array:
[
  { "repo": "circe-fs2", "stars": 14 },
  { "repo": "circe-config", "stars": 5 }
]

The appropriate pipe for the job also depends on your input stream value type (i.e. String, Byte or Segment[Byte]).

The following table sums up every pipe available as a function of the input stream value type as well as the JSON structure:

String Byte Segment[Byte]
Value stream stringStreamParser byteStreamParser byteStreamParserS
Array stringArrayParser byteArrayParser byteArrayParserS

As an example, let's say we have a stream of strings representing a JSON array, we'll pick the stringArrayParser pipe which converts a stream of String to a stream of Json, Circe's representation of JSONs:

import io.circe.fs2._
val stringStream: Stream[IO, String] = ...
val parsedStream: Stream[IO, Json] = stringStream.through(stringArrayParser)

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[IO, Json] = ...
val decodedStream: Stream[IO, Foo] = parsedStream.through(decoder[IO, 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.

circe-fs2's People

Contributors

aeons avatar arixmkii avatar armanbilge avatar benfradet avatar chwthewke avatar jatcwang avatar kubukoz avatar n4to4 avatar samspills avatar scala-steward avatar travisbrown avatar travisbrown-stripe avatar wedens avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.