Skip to content

Instantly share code, notes, and snippets.

import groovy.json.*
def jsonStr = '{"a": 1, "b": [{"c": 3, "d": 4}]}}'
def json = new JsonSlurper().parseText(jsonStr)
// XXX: first "de-array" `b`
json.b = json.b.first()
// next remove `c` from it
json.b.remove('c')
json.put('d',json.remove('b'))
println JsonOutput.toJson(json)