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

How to use akka-http-circe on client side calls?

I'm trying to do a simple REST API call using akka-http, circe and akka-http-json (akka-http-circe in particular). import io.circe.generic.auto._ object Blah extends FailFastCirceSupport { //... val fut: Future[Json] =…
akauppi
  • 17,018
  • 15
  • 95
  • 120
2
votes
1 answer

How to use generic in Scala from circe?

I want to use automatic generic marshaller to Json from circle: def printTest[T<: Product](resourse: ResourcePartTest[T]): Unit = { import io.circe.generic.auto._ import io.circe.syntax._ println(resourse.asJson) } But I can…
SuperMacho
  • 97
  • 10
2
votes
0 answers

Is there better way to just get an Json element from circe

I am a new user of circe api, currently I use following code to get an element from the JSON document: ((json.getOrElse(Json.Null) \\ name head) asString) get It look using more code then it should be, if there better suggestion?
carfield
  • 2,011
  • 2
  • 15
  • 15
2
votes
1 answer

Decoding Json with Circe when fields are incomplete

I have a transcript in json format with a bunch of words in it { "words": [{ "duration": 123, "name": "world" "time": 234, "speaker": null }] } I have been using Circe to encode/decode Json. In…
Alberto Centelles
  • 1,215
  • 11
  • 24
2
votes
1 answer

Parse JSON array as case class with Circe

Let's use this example JSON: { "bids": [ [16182.06, 0.02994158], [16179.56, 0.01902097], [16178.05, 0.06538498] ], "asks": [ [16191.92, 0.03597287], [16193.33, 0.0839688], [16194.95, 0.0857127] ] } Nothing special,…
Atais
  • 10,857
  • 6
  • 71
  • 111
2
votes
1 answer

Filter an object array to modify json with circe

I am evaluating Circe and couldn't find out how to use filter for arrays to transform a JSON. I read the guide on its website and API doc, still no clue. Help much appreciated. Sample data: { "Department" : "HR", "Employees" :[{ "name": "abc",…
fqye
  • 41
  • 6
2
votes
1 answer

Stack overflow in typeclass with implicit conversion

I made a generic DynamoFormat for Scanamo that would put any object that has Circe's Encoder and Decoder defined into database as a Json string. import com.gu.scanamo.DynamoFormat import io.circe.parser.parse import io.circe.syntax._ import…
Vasiliy Ivashin
  • 425
  • 2
  • 12
2
votes
0 answers

Scala macro compilation times

Working on a scala project that uses libraries such as circe, enumeratum, and shapeless We have a few enums defined namely, Region; EntityType and EntityAction eg sealed trait EntityAction extends EnumEntry with Hyphencase case object EntityAction…
Omar A
  • 103
  • 2
  • 5
2
votes
1 answer

Enforce a "at least one of two fields should be present" rule in Circe

I'm writing a Circe parser where the schema requires that at least one of two fields is set. This is quite specific and it doesn't seem to be a way to do it easily with Circe API. Let's call our fields text and html. I tried already to create a…
Chobeat
  • 3,445
  • 6
  • 41
  • 59
2
votes
1 answer

Encoding recursive data structure into Json with Circe when running on http4s

I am building a very simply service, that should return a tree like structure defined through a recursive case class: case class Node(id: Int, name: String, children: Seq[Node] = Seq()) But for some reason I keep getting a following compilation…
singleton
  • 326
  • 2
  • 13
2
votes
0 answers

Map Scala case class to JSON using Akka HTTP

I am trying to map the case class to the JSON Using the akka Http import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.PathMatchers.IntNumber import…
Vishal
  • 1,442
  • 3
  • 29
  • 48
2
votes
1 answer

How to serialize a Scala object to Json which already contains some Json

I have the following object which I am serializing to json using Circe case class Person(name: String, data: String) val x = Person("test", s"""{"a": 10, "b":"foo"}""") import io.circe._, io.circe.generic.auto._, io.circe.parser._,…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
2
votes
1 answer

circe type field not showing

When encoding to Json with circe we really want the type field to show e.g. scala> val fooJson = foo.asJson fooJson: io.circe.Json = { "this_is_a_string" : "abc", "another_field" : 123, "type" : "Foo" } This is taken from the release notes…
mattl
  • 2,082
  • 3
  • 17
  • 24
2
votes
1 answer

Encoding/Decode shapeless records with circe

Upgrading circe from 0.4.1 to 0.7.0 broke the following code: import shapeless._ import syntax.singleton._ import io.circe.generic.auto._ .run[Record.`'transaction_id -> Int`.T](transport) def run[A](transport: Json => Future[Json])(implicit…
simao
  • 14,491
  • 9
  • 55
  • 66
2
votes
2 answers

Circe decoder for scalaz.Maybe

Here's a simple finch server, using circe as decoder: import com.twitter.finagle.http.RequestBuilder import com.twitter.io.Buf import io.circe.generic.auto._ import io.finch._ import io.finch.circe._ case class Test(myValue: Int) val api =…
slouc
  • 9,508
  • 3
  • 16
  • 41