Groovy web console

subscribe to the feed Subscribe
to this
site
Remove nested json object (via #groovywebconsole)
tweet this snippet Tweet
this
script

Remove nested json object

Published 7 months ago by Nitin Dhomse with tags JSON Groovy
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.* 
def jsonStr = '''{
"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,
        "third": 12800,
        "fourth": 13000
    },
    "sell": true,
    "darn": 2,
    "rate": [{
        "busRate": 11900,
        "flag": false,
        "percent": 0
        }]
    }]
}'''

def json = new JsonSlurper().parseText(jsonStr) 
json.details[0].remove('goBus') 
println JsonOutput.toJson(json)