monix-circe


License

License

GroupId

GroupId

io.monix
ArtifactId

ArtifactId

monix-circe_2.12
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

monix-circe
monix-circe
Project URL

Project URL

https://github.com/monix/monix-circe
Project Organization

Project Organization

io.monix
Source Code Management

Source Code Management

https://github.com/monix/monix-circe

Download monix-circe_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.monix/monix-circe_2.12/ -->
<dependency>
    <groupId>io.monix</groupId>
    <artifactId>monix-circe_2.12</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.monix/monix-circe_2.12/
implementation 'io.monix:monix-circe_2.12:0.0.3'
// https://jarcasting.com/artifacts/io.monix/monix-circe_2.12/
implementation ("io.monix:monix-circe_2.12:0.0.3")
'io.monix:monix-circe_2.12:jar:0.0.3'
<dependency org="io.monix" name="monix-circe_2.12" rev="0.0.3">
  <artifact name="monix-circe_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.monix', module='monix-circe_2.12', version='0.0.3')
)
libraryDependencies += "io.monix" % "monix-circe_2.12" % "0.0.3"
[io.monix/monix-circe_2.12 "0.0.3"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.10
io.monix : monix-reactive_2.12 jar 3.2.2
io.circe : circe-jawn_2.12 jar 0.13.0
org.typelevel : jawn-parser_2.12 jar 1.0.0

test (4)

Group / Artifact Type Version
io.circe : circe-generic_2.12 jar 0.13.0
io.circe : circe-testing_2.12 jar 0.13.0
io.monix : minitest_2.12 jar 2.7.0
io.monix : minitest-laws_2.12 jar 2.7.0

Project Modules

There are no modules declared in this project.

Streaming JSON parsing for circe with Monix Observable Build Status Maven Central

Quick Start

To use monix-circe in an existing SBT project with Scala 2.12 or a later version, add the following dependencies to your build.sbt depending on your needs:

libraryDependencies ++= Seq(
  "io.monix" %% "monix-circe" % "0.0.3"
)

Parsing

Monix-Circe provides different pipes to parse your streams of JSONs depending on whether your Observable is:

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

The appropriate Operator for the job also depends on your input stream value type (i.e. String or Byte).

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

String Byte
Value stream stringStreamParser byteStreamParser
Array stringArrayParser byteArrayParser

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.Json
import monix.circe._
import monix.reactive.Observable

val stringStream: Observable[String] = ???
val parsedStream: Observable[Json] = stringStream.liftByOperator(stringArrayParser)

Decoding

Monix-Circe also comes with a decoder function which, given a Decoder[A], produces a Observable[Json] => Observable[A].

For example, using Circe's fully automatic derivation:

import io.circe.generic.auto._
case class Foo(a: Int, b: String)
val parsedStream: Observable[Json] = ???
val decodedStream: Observable[Foo] = parsedStream.liftByOperator(decoder[Foo])

Acknowledgements

Heavily inspired/based on circe-fs2 and circe-iteratee.

License

All code in this repository is licensed under the Apache License, Version 2.0. See LICENSE.txt.

io.monix

Monix

Asynchronous, Reactive programming for Scala and Scala.js

Versions

Version
0.0.3
0.0.2
0.0.1