Reputation: 35
how easily i can transform data ? I can searching data which interesting me, f. ex:
json \\ fieldName1 \\ fieldName2 \\ fieldName3
But how i can of this search modify value? f. ex
json transform{
case JField(x,y) => JField(x, z)
}
Upvotes: 1
Views: 1566
Reputation: 6609
If you use lift-json, you get exactly what you want :
scala> import net.liftweb.json._
scala> import net.liftweb.json.JsonDSL._
scala> val json =
("person" ->
("name" -> "Joe") ~
("age" -> 35) ~
("spouse" ->
("person" ->
("name" -> "Marilyn") ~
("age" -> 33)
)
)
)
scala> json transform {
case JField("name", JString(s)) => JField("NAME", JString(s.toUpperCase))
}
res8: net.liftweb.json.JsonAST.JValue = JObject(List(JField(person,JObject(List(
JField(NAME,JString(JOE)), JField(age,JInt(35)), JField(spouse,JObject(List(
JField(person,JObject(List(JField(NAME,JString(MARILYN)), JField(age,JInt(33)))))))))))))
The above codes are copied from the linked page.
If you don't use lift-json, you may take a look at kiama, as demonstrated in this answer.
Upvotes: 1