I have following JSON as an output:-
def desiredJson = '{"count": 4, "max": "12", "min": 0, "details": [{"goBus": {"first": 12800, "second": 11900, "third": 12800},"goAir": {"first": 12800, "second": 11900, "third": 12800}, "gotTrain": {"first": 12800, "second": 11900},"sell": true, "darn": 2,"rate": [{ "busRate": 11900, "flag": false, "percent": 0}],}],}'
I want to remove "count" key and its value, remove
"goBus": {
"first": 12800,
"second": 11900,
"third": 12800
},
And remove square brackets of "details" node.
I have tried below code to remove and replace as null:-
def slurper = new JsonSlurper();
def json = slurper.parse(file)
def newjson = JsonOutput.toJson(json).toString()
String j = "max"
newjson = newjson.replaceAll(""+ j +"", "")
log.info newjson
As an output, the max value is not getting removed. Or Is there any other way we can remove these all things from JSON.
Can anybody help me on this?
I have tried this also:-
def json = new JsonSlurper().parseText(desiredJson)
def njson = json.details.goBus
def pjson = njson.remove()
log.info JsonOutput.toJson(pjson)
It is returning false.