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
4
votes
2 answers

Scala Play Json Format for Map[Locale, String]

I have objects of type Map[java.util.Locale, String] How can I make Json Writes / Reads for this? I have looked at a couple other questions, but couldn't come up with a solution myself. I got (but not tested yet) something for Locale implicit val…
ticofab
  • 7,551
  • 13
  • 49
  • 90
3
votes
1 answer

How do I throw an error when an unknown field is present whilst reading JSON with Scala Play?

With JSON schemas, if you want the schema to fail validation if it finds any additional fields you can just throw an "additionalProperties": false on the schema and call it a day, a bit like this: { "$schema":…
James Whiteley
  • 3,363
  • 1
  • 19
  • 46
3
votes
2 answers

JsLookup on multiple level array using play Json library (or any other suggestion)

My function is receiving a JsValue, now this json have lists, and this lists element could also be lists, for example: { "firstName": "Elon", "lastName": "Musk", "companies": [ { "name": "Tesla", "city": "San Francisco", …
3
votes
2 answers

Conditional filtering of JSON before deserialisation to case class model

How to parse a JSON conditionally before deserialisation to the following case class: case class UserInfo(id: String, startDate: String, endDate: String) I have an implicit reads object UserInfo { implicit val reads: Reads[UserInfo] = ( …
vkt
  • 1,401
  • 2
  • 20
  • 46
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
  • 239
  • 2
  • 10
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,265
  • 1
  • 14
  • 31
3
votes
1 answer

Play framework: JSON Reads for a single-attribute case class

I'm trying to create a JSON Reads implicit for a case class that contains a single attribute, but I'm getting an error "Reads[Nothing] doesn't conform to expected type". Here's teh codes: import play.api.libs.functional.syntax._ import…
jbrown
  • 7,518
  • 16
  • 69
  • 117
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,501
  • 5
  • 27
  • 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,328
  • 2
  • 19
  • 32
2
votes
2 answers

How to check if JsArray holds Objects or Simple types?

I need to write a function that recieve JsValue, and do those steps: check if its of type Array if its NOT Array, return the value inside a list if it IS Array, check if its Array of an object or simple typle (string, boolean etc) if its Array of…
JohnBigs
  • 2,691
  • 3
  • 31
  • 61
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…
One.Punch.Leon
  • 602
  • 3
  • 10
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":…
trp86
  • 414
  • 1
  • 7
  • 21
2
votes
0 answers

BSON to Play JSON support for Long values

I've started using the play-json/play-json-compat libraries with reactivemongo 0.20.11. So I can use JSON Play reads/writes while importing the 'reactivemongo.play.json._' package and then easily fetch data from a JSONCollection instead of a…
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,561
  • 16
  • 27
1
2
3
20 21