This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |