Questions tagged [play-json]

The play.api.libs.json package contains data structures for representing JSON data and utilities for converting between these data structures and other data representations.

The play.api.libs.json package contains data structures for representing JSON data and utilities for converting between these data structures and other data representations. It includes the following types:

  • JsString
  • JsNumber
  • JsBoolean
  • JsObject
  • JsArray
  • JsNull
269 questions
3
votes
1 answer

How to filter JSON array results based on condition?

I'm using Scala Play 2.7.2 and have read ScalaJsonTransformers and ScalaJson. After calling a JSON API I get back (simplified MCVE) results like this: { "type": "searchset", "total": 5, "entry": [ { "start": "2019-06-07T09:00:00", …
SkyWalker
  • 11,704
  • 14
  • 65
  • 144
3
votes
1 answer

How to parse a json containing a field that always has a changed name in Scala?

I currently have a very big json response from an API that I want to json parse. My application is using play and in Scala. Doing this I'm using case classes which I will later parse using an implicit. But now I've realized inside one of my case…
GamingFelix
  • 229
  • 2
  • 10
3
votes
2 answers

No instance of play.api.libs.json.Format is available for scala.Predef.Map[java.lang.String, scala.Option[scala.Double]]

Trying to write a json format for an entity which contains a Map of Option. It throws following error Error:(8, 68) No instance of play.api.libs.json.Format is available for scala.Predef.Map[java.lang.String, scala.Option[scala.Double]] in the…
Sujit Kamthe
  • 613
  • 9
  • 12
3
votes
1 answer

Type parameter in play-json read/write macro

I have a parametrized case class CaseClass[T](name: String, t: T) for which I would like to have serialization/deserialization using play-json (2.5). Of course, I cannot have this if I do not have the equivalent for the type T, so I define object…
Cyrille Corpet
  • 5,120
  • 1
  • 11
  • 30
3
votes
1 answer

How can I convert between play.api.libs.json.JsValue and org.json4s.JValue

I'm using Play Framework to build an API, but need to perform some validation and transformation operations with a library that only speaks Json4s. So far, the only thing I've been able to get to work is converting to a string and parsing with the…
Matt Miller
  • 3,411
  • 5
  • 24
  • 26
3
votes
1 answer

Get concrete type of a case class

I have this: sealed trait Block sealed case class Header(param1: String, param2: String, ...) extends Block ... (more sealed case classes that follows the same…
Alejandro Echeverri
  • 1,178
  • 2
  • 16
  • 30
2
votes
1 answer

play-json OWrites for a class in trait which is implemented by an object of same name

When slick generates code, it's something like this (sample1/Tables.scala): package sample1 object Tables extends { val profile = ??? } with Tables trait Tables { case class Class1Row(num: Int) } I just want a dump of db objects using…
2
votes
1 answer

How to update a nested json using scala play framework?

I am trying to update a json value present within a json using Scala play framework.Instead of updating the value it is appending the value. val newJsonString = """{"P123": 25}""" val jsonStringAsJsValue = Json.parse("""{"counter_holders": {"Peter":…
trp
  • 384
  • 1
  • 5
  • 15
2
votes
1 answer

How to update each field in a list using Play json in Scala

I have the following json string: { "id":123, "students":[ { "collected":{ "field":"field_1" }, "attr":[{ "name":"test_name", "age":"17", "color":"blue" …
2
votes
1 answer

Play Json Reads nested generic serialized Json

Consider the following JSON { "a": "{\"b\": 12, \"c\": \"test\"}" } I would like to define a generic reads Reads[Outer[T]] for this kind of serialized Json import play.api.libs.json.{Json, Reads, __} final case class Outer[T](inner: T) final…
Nicolas Heimann
  • 2,361
  • 12
  • 25
2
votes
1 answer

How to update JSON with arrays of objects?

I'm trying to make a transformation to every object in an array in my JSON. The JSON looks something like this: { "foos": [ { "urls": ["www.google.com", "www.google.com", "www.stackoverflow.com"] }, { "urls":…
Billzabob
  • 33
  • 3
2
votes
1 answer

Scala Play readNullable can't read Map types

I am trying to use play.api.lib.json to convert a json to my object. But then this happend... case class Foo(foo:Option[Map[String,String]]) case class Bar(bar:String,foo:Foo) def barJsonToModel(foobarJson:JsValue):Bar = { implicit val…
2
votes
2 answers

Play Framework: No implicit format for Map

Using Play 2.5 I cannot seem to serialize a Map[SomeCaseClass, String] case class SomeCaseClass(value: String) implicit val formatSomeCaseClass = Json.format[SomeCaseClass] Json.toJson(Map[SomeCaseClass, String](SomeCaseClass("") -> "")) Errors…
Eduardo
  • 6,183
  • 12
  • 61
  • 109
2
votes
1 answer

Difference between validate and validateOpt in JsValue

JsValue has two methods def validate[A](implicit rds: Reads[A]): JsResult[A] - Tries to convert the node into a JsResult[T] (Success or Error). def validateOpt[A](implicit rds: Reads[A]): JsResult[Option[A]] - I suppose it also does the same…
Manu Chadha
  • 11,886
  • 11
  • 51
  • 115
2
votes
1 answer

Exclude certain fields during serialization using play-json-extensions

I have a case class that is having more than 22 parameters and to serialize this case class I am using json-play-extension. Pseudo code is as follows case class Foo(a1: Int,a2: Int,a3: Int,...,a24: Int) I have an implicit for Foo as…
Chaitanya Waikar
  • 2,686
  • 8
  • 26
1
2
3
17 18