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
0
votes
0 answers

Decoding Option[Array[String]] field of a case class with circe

I am trying to decode a case class from JSON which contains fields that are defined as Option[Array[T]] and get decode failure when this field is missing. The decoder from circe is the default. case class Quotation(BasicCover: Option[BasicCover], …
Dimitris
  • 13
  • 1
  • 4
-1
votes
1 answer

Scala: How to decode a List of objects with Circe

My GreedIndex decoder is not working but I cannot seem to figure out why; I reckon it is something really silly. I'm thinking it might be the timeStamp or problems with List[CryptoData] case class CryptoData(greedValue: String, valueClassification:…
Ry2254
  • 859
  • 1
  • 10
  • 19
-1
votes
1 answer

Circe Decoding "AnyContentAsJson" type in Scala Play

I am trying to parse the body of an incoming request to JSON using Circe and Scala Play. The incoming request is coming from Postman as I'm running the service locally for testing purposes. The decode I am using is:…
lmcphers
  • 468
  • 3
  • 18
-1
votes
3 answers

Using Scala to represent two JSON fields of which only one can be null

Let's say my API returns a JSON that looks like this: { "field1": "hey", "field2": null, } I have this rule that only one of these fields can be null at the same time. In this example, only field2 is null so we're ok. I can represent this in…
LLCampos
  • 295
  • 4
  • 17
-2
votes
3 answers

entity decode for json that return a list/seq of any val

I am building the back-end of an app using http4s. In the app i receive a json response from an external api (not the one i am working on). The api response is of this pattern below. json response: `{ "datatable" : { "data" :…
-2
votes
1 answer

Modifying a JSON array in Scala with circe

I have a JSON string with array as the following: { "cars": { "Nissan": [ {"model":"Sentra", "doors":4}, {"model":"Maxima", "doors":4} ], "Ford": [ {"model":"Taurus", "doors":4}, {"model":"Escort",…
Doe
  • 11
  • 1
1 2 3
26
27