Questions tagged [circe]

Circe is a JSON library for Scala (and Scala.js).

Circe is a JSON library for Scala powered by Cats.

A simple usage of this library is:

import io.circe._, io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._

sealed trait Foo
case class Bar(xs: Vector[String]) extends Foo
case class Qux(i: Int, d: Option[Double]) extends Foo

val foo: Foo = Qux(13, Some(14.0))

val json = foo.asJson.noSpaces
println(json) // prints: {"Qux":{"i":13,"d":14}}

val decodedFoo = decode[Foo](json)
println(decodedFoo) // prints: Right(Qux(13,Some(14)))

For reading about it please refer:

396 questions
5
votes
0 answers

could not find implicit value for evidence parameter of type io.finch.Decode.Json

Has been working on this for a couple of days and still have no clue what's going on: Got a finch web service, the build.sbt dependencies look like: "com.github.finagle" %% "finch-circe" % finchVersion changing(), "com.github.finagle" %%…
Shi Chen
  • 91
  • 2
  • 7
5
votes
1 answer

Circe cannot find implicit encoder

I am trying to encode a few classes into json strings, however no matter what I try, my classes do not seem to be able to find an implicit encoder for the case classes I am using. Here's the smallest example I was able to pare it down to. import…
Davis Broda
  • 4,102
  • 5
  • 23
  • 37
5
votes
1 answer

Incompatible Jackson version: 2.7.1 in sbt?

I'm getting this error when running TwitterServer from sbt: SEVERE: LoadService: failed to instantiate 'com.twitter.finagle.stats.MetricsExporter' for the requested service…
mikebridge
  • 4,209
  • 2
  • 40
  • 50
4
votes
1 answer

How to parse json to case class with map by jsonter, plokhotnyuk

I want to read json messages from Kafka and put them into another structure of SpecificRecordBase class (avro). The part of the json has dynamic structure for example {"known_type": "test", "unknown_type": {"attr1": true, "attr2": "value2",…
Vadim
  • 753
  • 8
  • 22
4
votes
0 answers

PostgreSQL Error with Doobie: PSQLException: The column index is out of range: 3, number of columns: 2

I am practicing with Scala, Doobie and PostgreSQL. The database is within a Docker container. I am able to post and update jobs but unable to GET all posts. I keep getting the below error. I have researched other similar questions but my differs as…
Ry2254
  • 859
  • 1
  • 10
  • 19
4
votes
1 answer

How to create a decoder for an Either type with Circe?

If you are expecting to receive either a Json of a type A or type B (Either[A, B]), how could you write a decoder for it? For example, let's say you are building a client for an external API that can answer with some expected Json structure: { …
Camilo Sampedro
  • 1,306
  • 1
  • 19
  • 32
4
votes
1 answer

Alternative to parsing json with option [ either [A,B ] ] in scala

For example, here payload is optional and it has 3 variants: How can I parse the json with types like option[either[A,B,C]] but to use abstract data type using things sealed trait or sum type? Below is a minimal example with some boiler…
cpchung
  • 774
  • 3
  • 8
  • 23
4
votes
1 answer

Transforming JSON with Circe

Suppose I have some JSON data like this: { "data": { "title": "example input", "someBoolean": false, "innerData": { "innerString": "input inner string", "innerBoolean": true, …
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
4
votes
3 answers

could not find implicit value for parameter encoder: io.circe.Encoder[com.sweetsoft.SapHealth]

I have the following code, that does not compile: import java.time.Instant import io.circe.{Decoder, Encoder} import io.circe.generic.auto._ import io.circe.syntax._ trait SapHealth {} case class SapHealthRejected(reason: String) extends…
softshipper
  • 32,463
  • 51
  • 192
  • 400
4
votes
2 answers

Why it does not decode to ADT type?

I am trying to derive the following string into a proper ADT type: res6: String = {"raw":"Hello","status":{"MsgSuccess":{}}} and using the circe library. The ADT type looks as the following: sealed trait MsgDoc { } final case class…
softshipper
  • 32,463
  • 51
  • 192
  • 400
4
votes
1 answer

Modify json field type via circe

I have simple Json: val str = """{"test":"123"}""" How I can modify String "123" to Int 123 to get new Json?: {"test":123} Now I am using: val json = parse(str).getOrElse(Json.Null) val jsObj = json.asObject.get // Unsafe, just example val…
Oleg
  • 899
  • 1
  • 8
  • 22
4
votes
3 answers

How to create a custom decoder in Circe that parses time values

I am trying to decode a string of the form "5m" or "5s" or "5ms" into objects of type FiniteDuration that are, respectively, 5.minutes, 5.seconds, 5.milliseconds. I am trying to create a custom decoder and encoder for a project that involves the…
Allen Han
  • 1,163
  • 7
  • 16
4
votes
1 answer

Decode Case class with nested Coproduct by discriminator

I have a the following set up case class A(eventType : String, fieldOne : Int) case class B(eventType : String, fieldOne : Int, fieldTwo : Int) type Event = A :+: B :+: CNil case class X(id :String, events : List[Event]) And I receive the…
John Cragg
  • 201
  • 1
  • 2
  • 4
4
votes
0 answers

@ConfiguredJsonCodec doesn't work with additional constructor

import io.circe.generic.extras.{Configuration, ConfiguredJsonCodec} @ConfiguredJsonCodec case class Foo(firstName: String) object Foo { implicit val snakeConfiguration=Configuration.default.withSnakeCaseMemberNames} after parsing…
4
votes
1 answer

Circe: force an optional field to `null`

Is there a way to serialize a single None field to "null" ? For example: // When None, I'd like to serialize only f2 to `null` case class Example(f1: Option[Int], f2: Option[Int]) val printer = Printer.noSpaces.copy(dropNullValues =…