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

Type parameter for implicit valued method in Scala - Circe

I'm new to Scala, and using circe to model and serialize some API responses. I find myself using the following boilerplate sealed trait SomeTrait object SomeTrait { implicit val someEncoder: Encoder[SomeTrait] = deriveEncoder[SomeTrait] …
Eliran Abdoo
  • 611
  • 6
  • 17
2
votes
2 answers

Pattern matching on a Scala case class with `type` as a field

I have a case class defined for JSON parsing using the Circe library: final case class Event( source: Option[String], nonce: Option[Int], `type`: Option[Any], tag: Option[String], payload: Option[Any], blockOrder:…
Vishakh
  • 1,168
  • 1
  • 11
  • 20
2
votes
1 answer

http4s json handling in authed routes

I am using Scala 3 and http4s 1.0.0-M35. I want to use auth with json handling. val routes = AuthedRoutes.of[User, IO] { case request@POST -> Root / "dialog" / LongVar(dialogId) / "send" as user => { for { sendMessageRequest <-…
LIshy2
  • 150
  • 6
2
votes
3 answers

How to ignore a field from serializing when using circe in scala

I am using circe in scala and have a following requirement : Let's say I have some class like below and I want to avoid password field from being serialised then is there any way to let circe know that it should not serialise password field? In…
Hitesh
  • 432
  • 3
  • 13
2
votes
0 answers

Changing stored JSON's field's value with slick-pg

I'm using slick-pg with circe-json and I'm a bit stuck. I wonder is it possible to modify not the whole JSON, but only the value of a field? I can update JSON like this: db.run { questQuery.filter(_.json.+>>("name") === name.bind) …
Akechik
  • 21
  • 1
2
votes
1 answer

Parsing recursive JSON structure with Lists in Scala

I've got the following JSON structure and I can't find a good way to parse it in Scala (I'm using circe BTW): { "name": "xx", "args": [ {"name":"xy", "args": []}, [ {"name":"xy", "args": []}, {"name":"xy", "args": [[]]} …
fr3ak
  • 493
  • 3
  • 16
2
votes
1 answer

Filter resulting JSON using circe

I have a JSON object that I've transformed that I need to filter down to only a subset of its original keys. I've looked through the docs for the Json object in circe but it doesn't appear to expose any API around filtering the object. Do I have to…
gstranger
  • 53
  • 2
2
votes
1 answer

Parse Array with circe

i have a json such as : [ [ "Service ID", "VARCHAR", 1, 12 ], [ "Operation", "VARCHAR", 2, 12 ], [ "Start Date", "VARCHAR", 3, 12 …
Flow
  • 57
  • 5
2
votes
1 answer

How do I convert a java.util.UUID to doobie.syntax.SqlInterpolator.SingleFragment?

I am trying to set up a simple scala app with database using doobie, http4s and circe. How do I convert a java.util.UUID to doobie.syntax.SqlInterpolator.SingleFragment ? final case class User(id: UUID, details: UserDetails) implicit val…
Ry2254
  • 859
  • 1
  • 10
  • 19
2
votes
1 answer

ConfiguredJsonCodec for snake case ADT

I have to consume a json api, where there is a list of discrete string values in snake case. The example below works, but I would like to remove the manual fooDecoder in favor of the (currently commented out) ConfiguredJsonCodec annotation. Or more…
Saskia
  • 1,046
  • 1
  • 7
  • 23
2
votes
2 answers

How can I deserialize an non-fixed array of jsons using Circe's manual decoder?

I have a JSON that looks like: { "data": [ { "id": "1", "email": "hello@world.com", "name": "Mr foo", "roles": [ "Chief Bar Officer" ], "avatar_url": null, "phone_number": null }, { …
alt-f4
  • 2,112
  • 17
  • 49
2
votes
2 answers

Why does the circe `or` function (an apparently unary function) work with reduceLeft which requires a binary op?

A and I are doing some work with circe to encode/decode some ADTs and we ran into some functionality we fundamentally don't understand. The examples given in the circe documentation work as expected, but upon drilling down - it's not clear why the…
2
votes
2 answers

Circe: Moving an Implicit Encoder into A Generic Class

I am working with the Circe library and want to learn the ropes. Consider the following code: import io.circe.generic.auto._ import io.circe.syntax._ import io.circe.{Decoder, Encoder, Json} sealed trait Something case class Name(val name: String)…
finite_diffidence
  • 893
  • 2
  • 11
  • 20
2
votes
1 answer

decoder for refined type when using circe with Http4s

I am trying to use refined types for a case class but couldn't figure out how the encoder will actually work. For json parsing circe is used with https4s library. type AgeT = Int Refined Interval.ClosedOpen[0,100] type NameT = String Refined…
Abhi
  • 130
  • 11
2
votes
0 answers

How to write json to file (scala, circe)?

I'm trying to figure out the way how to write json to archive file/stream. Try { val baos = new ByteArrayOutputStream val zos = new ZipOutputStream(baos) series.foreach { s => val entry = new…
ibanezn04
  • 478
  • 5
  • 12