我稍微改写了你的转换,当我根据你的输入尝试它时,这似乎奏效了:
val transformedJson2 = parsedInput transform {
case JField("name2", fields) =>
fields remove {
case JField("dsc1", _) => true
case _ => false
}
}
除了使用,您还可以像在示例中那样remove
使用第二个:transform
val transformedJson2 = parsedInput transform {
case JField("name2", fields) =>
fields transform {
case JField("dsc1", _) => JNothing
}
}
因此,通过使用来自以下的解析输入:
scala> val parsedInput = parse(""" {
| "group": {
| "name1":{
| "dsc":"some dsc",
| "dsc1":"some dsc",
| "dsc2":"some dsc"
| },
| "name2":{
| "dsc":"some dsc",
| "dsc1":"some dsc",
| "dsc2":"some dsc"
| }
| }
| } """)
parsedInput: net.liftweb.json.package.JValue = JObject(List(JField(group,JObject(List(JField(name1,JObject(List(JField(dsc,JString(some dsc)), JField(dsc1,JString(some dsc)), JField(dsc2,JString(some dsc))))), JField(name2,JObject(List(JField(dsc,JString(some dsc)), JField(dsc1,JString(some dsc)), JField(dsc2,JString(some dsc))))))))))
两者都应该产生输出:
scala> pretty(render(transformedJson2))
res10: String =
{
"group":{
"name1":{
"dsc":"some dsc",
"dsc1":"some dsc",
"dsc2":"some dsc"
},
"name2":{
"dsc":"some dsc",
"dsc2":"some dsc"
}
}
}