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

Encountering errors when trying to write either a Circe encoder or decoder for ADT

I'm trying to write some code based on Circe's documentation, however, trying to compile both my encoder and decoder results in an error. If you would like to take a look at the entire project, you can do so on github (link to the file I have issues…
TomPoczos
  • 95
  • 1
  • 9
2
votes
1 answer

sbt compile fails with bad option: '-Ywarn-macros:after'

With a build.sbt file like: ThisBuild / organization := "com.company" ThisBuild / version := "1.0.0-SNAPSHOT" ThisBuild / scalaVersion := "2.11.12" Global / concurrentRestrictions += Tags.limit(Tags.Test, 1) Global / scalacOptions ++=…
Metropolis
  • 2,018
  • 1
  • 19
  • 36
2
votes
1 answer

Akka Http / Circe Decode Result

I apologize if I'm missing something simple, but I'm trying to use Akka HTTP with Circe (using the akka-http-json Circe module). I'm trying to retrieve the results of a GET call in a ScalaTest which mixes in the ErrorAccumulatingCirceSupport trait. …
Timothy Perrigo
  • 723
  • 4
  • 18
2
votes
2 answers

How to represent dynamic JSON keys in Scala when using circe

I'm trying to represent the following JSON as a Scala case class: { "cars": { "THIS IS A DYNAMIC KEY 1": { "name": "bla 1", }, "THIS IS A DYNAMIC KEY 2": { "name": "bla 2", …
Rory
  • 798
  • 2
  • 12
  • 37
2
votes
1 answer

How to use Hcursor or Optics, as part of Circe-Json, to return a List of matching Objects?

I have code which looks roughly like this: val json: Json = parse(""" [ { "id": 1, "type": "Contacts", "admin": false, "cookies": 3 }, { "id": 2, "type": "Apples", "admin": false, "cookies": 6 }, { "id": 3, "type": "Contacts", "admin":…
x25pads
  • 35
  • 1
  • 5
2
votes
0 answers

Not able to Decode when using Circe JsonKey

Not able to map JsonKey when decoding it back to Scala case class. sealed trait Alert @ConfiguredJsonCodec case class Free(@JsonKey("aa aa") i:Int, j:Int) extends Alert object Free{ implicit val config:…
Amitoj Singh
  • 77
  • 1
  • 10
2
votes
1 answer

Circe Decoder - Fallback to another decoder if fails

I am using Circe for json operations. I have added custom encoders and decoders to handle some of the types, like Joda Time. While parsing DateTime, I want to allow multiple formats to be passed. For eg. dd-MM-yyyy'T'HH:mm:ss'Z' and…
Yadu Krishnan
  • 3,492
  • 5
  • 41
  • 80
2
votes
1 answer

Scala circe decode Map[String, String] type

I have a Map[String, String] object with I want to use as json. I have written an encoder for this type: implicit val encodeMap: Encoder[Map[String, String]] = new Encoder[Map[String, String]] { override def apply(values: Map[String, String]):…
Doe
  • 71
  • 1
  • 4
2
votes
2 answers

How to write a custom decoder for [Option[Option[A]] in Circe?

I had written a Reads converter in play-json for Option[Option[A]] that had the following behavior: //given this case class case class MyModel(field: Option[Option[String]]) //this JSON -- maps to --> this MyModel: //"{ \"field\": \"value\" }" -->…
Lasf
  • 2,536
  • 1
  • 16
  • 35
2
votes
1 answer

circe automatic derivation - struggling with the imports

I have a method exposed on my API that looks like this: def read[T](implicit decoder: Decoder[T]): T A user can bring along any T they like and my code will attempt to parse the json result into a T. The issue I want to resolve is that any user…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
2
votes
1 answer

Encode Map[String, MyCaseClass] into Seq[String, String] using circe

As per the question, how to encode Map[String, MyCaseClass] into Seq[String, String] using circe? Model: case class MyCaseClass(name: String, enabled: Boolean) case class Parent(parentName: String, collection: Map[String,…
Rory
  • 798
  • 2
  • 12
  • 37
2
votes
1 answer

Summoning Encoder[OneAnd[NonEmptyList, Int]]?

Given: @ import $ivy.`io.circe::circe-core:0.9.3` import $ivy.$ @ import $ivy.`io.circe::circe-generic:0.9.3` import $ivy.$ @ import cats._, cats.data._, io.circe._, io.circe.Encoder._,…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
2
votes
1 answer

Shapeless: could not find implicit for Coproduct mapping

I have the following code which uses circe to deserialize a json which can have two shapes (see the values of jsonPersonalDetails and jsonPersonalAddress). When I try to call the method transform from SearchCriteria, I get: Error:(38, 26) could…
Octavian R.
  • 1,231
  • 8
  • 12
2
votes
1 answer

Custom circe decoder for variant json-field

How can I write circe decoder for class case class KeyValueRow(count: Int, key: String) where json contains field "count" (Int) and some extra string-field (name of this field may be various, like "url", "city",…
Pavel Ajtkulov
  • 515
  • 7
  • 21
2
votes
0 answers

Using Circe to parse JSON array into case class without specifying the tupled type

I have a structure that looks like so: case class BfxCandle(mts: Long, open: Float, close: Float, high: Float, low: Float, volume: Float) It's JSON encoding is the following: [1000, 10, 10, 10, 10, 100] And it's companion class features a…
Ploo
  • 417
  • 1
  • 5
  • 12