简体   繁体   English

groovy 移除 json 无水阵列 label

[英]groovy to remove json unwated array label

I have this json and I want to remove the field item.我有这个 json,我想删除字段项。

{ "field": "AAA", "list": { "item": [ { "field01": "111", "field02": "222" }, { "field01": "333", "field02": "444" } ] }}

I'm using this json slurper groovy but it's returnung null.我正在使用这个 json slurper groovy 但它返回 null。

def myJson = '..' //above json; def jsonParser = new JsonSlurper(); def jsonObject=jsonParser.parseText(myJson); return JsonOutput.toJson(jsonObject["item"])

The expected output is:预期的 output 为:

{ "field": "AAA", "list": [ { "field01": "111", "field02": "222" }, { "field01": "333", "field02": "444" } ]}

How can I do to remove the field "item"?如何删除“项目”字段?

def myJson = '..' //above json; 
def jsonParser = new JsonSlurper(); 
def jsonObject=jsonParser.parseText(myJson); 
jsonObject.list=jsonObject.list.item
return JsonOutput.toJson(jsonObject)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM