Created
August 7, 2020 03:40
-
-
Save kolattukudy/1618e84f1606fd556d15a18b77027190 to your computer and use it in GitHub Desktop.
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment