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
313 questions
2
votes
2 answers

How to write implicit Writes for case class having more than 22 fields

case class Foo( _1:Int,_2:Int,_3:Int,_4:Int,_5:Int, _21:Int,_22:Int,_23:Int,_24:Int,_25:Int, _31:Int,_32:Int,_33:Int,_34:Int,_35:Int, _41:Int,_42:Int,_43:Int,_44:Int,_45:Int, _51:Int,_52:Int,_53:Int,_54:Int,_55:Int ) For a case class like…
sowmiyaksr
  • 169
  • 5
  • 18
2
votes
1 answer

Play JsPath writes for Infinite Double

I am trying to implement a function writing Doubles that might have a value of Infinity (which does not exist in JSON). Here are some examples of what I am trying to achieve: Input: Double.PositiveInfinity Output: { "positiveInfinty": true, …
Tyler
  • 17,669
  • 10
  • 51
  • 89
2
votes
1 answer

Why isn't a member of type Option[String] being serialized?

I have a dummy class Foo which has three members: import play.api.libs.json.Json case class Foo(id: String, fooType: FooType, nextId: Option[String]) object Foo { implicit val fooReads = Json.reads[Foo] implicit val fooFormat =…
erip
  • 16,374
  • 11
  • 66
  • 121
2
votes
1 answer

Create and fill a JsArray with play-json transformer

With Play/Scala, I try to transform this json: val json = Json.parse(""" { "name": "John Doe", "location": { "lon": 48.858596, "lat": 2.294481 } } """) into this result: val result = Json.parse(""" { "name": "John Doe", …
Chrissom
  • 23
  • 4
2
votes
0 answers

op-rabbit: How do I set the content-type in messages sent from RabbitMQ server to my subscriber?

I have set up a direct exchange on my RabbitMQ server. I publish messages to that server as shown: val message = Json.toJson(myMessage).toString subscriber.rabbitControl ! Message.exchange(message, routingKey = "MyMessage", exchange = "ipsmse") My…
Shafique Jamal
  • 1,550
  • 3
  • 21
  • 45
2
votes
1 answer

Play Framework can't import play-json implicit reader & writer

I have a controller in Play Framework (2.5.4) managed by sbt. userController.scala package controllers // import models.User import com.neruti.User import play.api._ import play.api.mvc._ import play.api.libs.json._ import…
Cheng Ping Onn
  • 687
  • 1
  • 8
  • 17
2
votes
3 answers

Sequence a List[JsResult[A]] to a JsResult[List[A]]

I am attempting to make an API for stripe which involves a lot of mapping from Json to case classes (and vice versa). I have come across an issue where I end up with a List[JsResult[A]] (this is the result of mapping through a list of JObject's and…
mdedetrich
  • 1,899
  • 1
  • 18
  • 29
2
votes
1 answer

Error in converting class with enum attribute to Json with Play 2.3 and Scala 2.11.1

i have a case class User with an Enum as one of its attributes i want to convert this class into Json using Play-Json api but i am getting error here is my User class case class User ( name : String= "", id : String = "", status : UserStatus =…
M.Ahsen Taqi
  • 965
  • 11
  • 35
2
votes
1 answer

Separating validation constraints from unmarshalling

I've come across this article that demonstrates the new play validation API in conjunction with shapeless. I fail to recreate the code snippets though (probably because I don't know where to import from). import play.api.libs.json._ import…
Taig
  • 6,718
  • 4
  • 44
  • 65
2
votes
1 answer

Cannot resolve Writes[T] at compile time in Play Json

I am trying to make a generic Writer to get me the String representation of a json with Play Json. What I've got till now is import com.twitter.finatra.http.Controller import play.api.libs.json.{Json, Writes} trait MyController extends Controller…
Tomas Duhourq
  • 81
  • 1
  • 6
2
votes
2 answers

Scala key/value case class to Json

Given the following case class: case class ValueItem(key: String, value: String) and the following json formatter: implicit val valueItemFormat: Format[ValueItem] = ( (__ \ "key").format[String] and (__ \…
Dario
  • 255
  • 1
  • 10
1
vote
3 answers

Scala play json: how to capture the whole JSON source?

I receive, in my client, a WSResponse, and use play's deserializeJson method to extract the data, specified by paths, e.g. implicit val lsmf: Format[MyData] = ( (__).formatNullable[JsValue] ~ (__ \ "id").format[Int] ~ (__ \…
Vlad Patryshev
  • 1,379
  • 1
  • 10
  • 16
1
vote
2 answers

JSON parsing removes decimal trailing zeros

I have a Json string, after parsing I want it to remain in decimal form. import play.api.libs.json._ val jsonString = """{"value":2.0}""" println(jsonString) println(Json.parse(jsonString)) The output of the code above…
codeMouse
  • 31
  • 3
1
vote
1 answer

play framework json lookup inside array

I have simple json: { "name": "John", "placesVisited": [ { "name": "Paris", "data": { "weather": "warm", "date": "31/01/22" } }, { "name": "New York", "data": [ { …
JohnBigs
  • 2,691
  • 3
  • 31
  • 61
1
vote
1 answer

Diverging Implicit Error When Parsing JSON to Case Class in Scala

I'm facing a strange error where I'm trying to parse a JSON String into a generic case class. My case class looks like this: final case class LocationAPIObject[F[_]]( countryCode: F[String], partyId: F[String], uid: F[String] ) For a JSON…
joesan
  • 13,963
  • 27
  • 95
  • 232