Since the documentation is a bit scarce, I put together a small guide to keep people from having to check out the source code.
For the purpose of the tutorial, let’s say that we have the following
which we wish to parse and decode as the following
Popularity case class:
circe-fs2 offers three different strategies to parse your stream of JSONs depending on the type of your input stream.
If you have a stream of strings you can parse it using
If you have a stream of bytes, you can rely on
Note that this parser hasn’t been published yet, you’ll have to compile circe-fs2 from source if you want to use it.
Finally, if you have a stream of chunked bytes, you can use
We now have a
Stream[F[_]], Json], where
Json is Circe’s way of representing a JSON.
Now that we have a stream of
Jsons, we can rely on circe-generic to automatically derive a
Decoder for our
Popularity case class and turn our stream into a
We can now run our stream:
I hope this introduction proved useful.
You can find a full gist at https://gist.github.com/BenFradet/a69e3fa86ad2654ed017e2cb2881c307.