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
4
votes
1 answer

Decoded circe array inside case class always failing case class comparison test?

For this case class: import io.circe.generic.JsonCodec @JsonCodec case class Stuff(things: Array[String]) This test passes ok (case class to json test): import io.circe.parser.decode import io.circe.syntax._ import org.scalatest._ val caseClass =…
Rory
  • 798
  • 2
  • 12
  • 37
4
votes
2 answers

Parse Json Objects into case classes in Scala?

I have an array of Json objects. All of these objects follow one of two structures: The first like this: { "uuid": "321, "uuidType": "series", "title": "a movie", "segments": [ …
Nespony
  • 1,253
  • 4
  • 24
  • 42
4
votes
2 answers

How to decode null to empty string in Circe

I have the following case class case class Response(attributes: CsvAttributes, rows: Seq[Array[String]]) The rows are obtained from a Java library which can have null elements in the array as shown below: [ ["a", "b", null], ["c", null,…
Gowrav
  • 627
  • 7
  • 22
4
votes
2 answers

Http4s EntityDecoder not being auto derived for simple case class

I am getting this error: Cannot decode into a value of type com.blah.rest.model.UserProfile, because no EntityDecoder[cats.effect.IO, com.blah.rest.model.UserProfile] instance could be found. for the following case class: case class…
iyerland
  • 632
  • 2
  • 10
  • 24
4
votes
1 answer

Circe: decoding a container type with different possible content types

My goal is to transform JSON into the following model: case class Container(typeId: Int, timestamp: Long, content: Content) sealed trait Content case class ContentType1(...) extends Content case class ContentType2(...) extends Content case class…
ceran
  • 1,392
  • 1
  • 17
  • 43
4
votes
1 answer

How to avoid scientific notation in circe JSON serialization

Let's say I have the next case class: case class Person(id: String, money: BigDecimal) object Person { implicit val encoder: Encoder[Person] = Encoder.forProduct2("ID", "Money")(u => (u.id, u.money)) I want to serialize instances of the…
Iván Portilla
  • 461
  • 1
  • 3
  • 13
4
votes
1 answer

Circe: decode multi-level ADT efficiently

I want to decode the following ADT with Circe: sealed trait PaymentType object PaymentType extends EnumEncoder[PaymentType] { case object DebitCard extends PaymentType case object Check extends PaymentType case object Cash extends…
Haspemulator
  • 11,050
  • 9
  • 49
  • 76
4
votes
1 answer

`circe` Type-level Json => A Function?

Using circe or argonaut, how can I write a Json => A (note - Json may not be the name of the type) where A is given by the SSN class: // A USA Social Security Number has exactly 8 digits. case class SSN(value: Sized[List[Nat],…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
3
votes
2 answers

Encode nested object as a string

Given the following case classes: case class Mailbox(value: String) case class Group(objectType: String, mailbox: Mailbox) I am attempting to find a way to encode a Group object as follows where mailbox is encoded as a string value, rather than an…
Andrew Kirk
  • 1,774
  • 1
  • 14
  • 16
3
votes
1 answer

Scala, PureConfig - how to read json config file?

I have a simple config.json file in my resources: { "configs": [ { "someConfig": { "name": "my_name", "filters": { "name": "new" }, "id": "some-config-id", "fixes": { "isFixed":…
Developus
  • 1,400
  • 2
  • 14
  • 50
3
votes
2 answers

Scala Circe. Encoder type Any

I am trying encode class ResponseResult to json case class ResponseResult (var Code : Int, var Message: String, var Data: Any ) var json = ResponseResult(1, "2", List(3,4,5)).asJson I get an error could not find…
Hiep Le
  • 323
  • 2
  • 13
3
votes
1 answer

Circe,Tapir and JodaTime

I have a case class like final case class MyClass(id: Long, eventData: EventsDTO) final case class EventsDTO( customerId: Long, eventName: String, processTime: DateTime //JodaTime ) I have custom encoder and decoder as val…
Arjun Karnwal
  • 379
  • 3
  • 13
3
votes
1 answer

Tapir Custom Codec

I am stuck at a place, I am using scala, tapir and circe. sealed abstract class S1Error extends Product with Serializable object S1Error { final case class SError(error: SMError) extends S1Error } sealed abstract class SMError(message:…
Arjun Karnwal
  • 379
  • 3
  • 13
3
votes
0 answers

Tapir - List type for input parameter not working

I am defining an API endpoint using tapir which goes like this import io.circe.generic.auto._ import sttp.model.StatusCode import sttp.tapir.json.circe._ import sttp.tapir._ val endpo: Route[List[String], String] = endpoint.post …
Arjun Karnwal
  • 379
  • 3
  • 13
3
votes
2 answers

object circe is not a member of package io

I am trying to create a predef.sc file for ammonite REPL. This is what I have written val fs2Version = "2.2.2" val circeVersion = "0.13.0" // fs2 interp.load.ivy("co.fs2" %% "fs2-core" % fs2Version) import scala.collection.immutable.{Stream =>…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373