Is it possible to add new field to JsObject?
val jsonObj = Json.obj()
jsonObj.put("field" -> 100) <==== Somthing like this
I have a lot of methods that add new fields. How can I dynamically create JsObject?
Is it possible to add new field to JsObject?
val jsonObj = Json.obj()
jsonObj.put("field" -> 100) <==== Somthing like this
I have a lot of methods that add new fields. How can I dynamically create JsObject?
Yes, you can add a new field using the "+" method. Note that the object is immutable, so this will create a new copy of the JsObject with the added field:
val obj = Json.obj()
// obj - {}
val newObj = obj + ("name" -> JsString("Kip"))
// newObj - {"name":"Kip"}
© 2022 - 2024 — McMap. All rights reserved.
play.api.libs.json...
objects are immutable – Mathison