scalaplay-json

update JsObject value for a specific key


lets say I have this simple json as JsObject:

val simpleJson = Json.parse("""{
                       "name" : "Watership Down"
                       }""".stripMargin).as[JsObject]

and I want to change the "name" value, how would I do that on JsObject?


Solution

  • simpleJson ++ JsObject(Map("name": JsString("Spaceship Up")))
    

    ++ merges two JsObjects, with the right-hand-side taking precedence.