100) <==== ...">

Play2 adds a new field to JsObject

Is it possible to add a new field to JsObject?

val jsonObj = Json.obj()
jsonObj.put("field" -> 100) <==== Somthing like this

I have many methods that add new fields. How can I dynamically create a JsObject?

+4
source share
1 answer

Yes, you can add a new field using the "+" method. Note that the object is immutable, so this will create a new copy of JsObject with the field added:

val obj = Json.obj()
// obj - {}
val newObj = obj + ("name" -> JsString("Kip"))
// newObj - {"name":"Kip"}
+9
source

Source: https://habr.com/ru/post/1529268/


All Articles