JsObject and JsValue solves almost the same purpose but in JsObject
val data[JsObject] = Json.obj("id1"-> "some_id1")
val newData[JsObject] = data ++ Json.obj("id"-> "some_id")
we can add a new key-value pair in JsObject but I still haven't figure out how to add a key-value pair in JsValue
You use the JSValue class to convert basic values, such as numbers and strings, between JavaScript and Objective-C or Swift representations to pass data between native code and JavaScript code.
The Play JSON API provides implicit Writes for most basic types, such as Int , Double , String , and Boolean . It also supports Writes for collections of any type T that a Writes[T] exists. import play. json.
You can do more with JsObject because it is a subclass of JsValue that represents a JSON object ({...}). JsValue can be a string, numeric, object or array. Therefore you can't assume that it has key value pairs. If you have a val x: JsValue that you know is a JsObject you can use x.as[JsObject] to cast it or if you're not sure it's a JsObject you can use x.asOpt[JsObject] to get an Option[JsObject].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With