Skip to content

Instantly share code, notes, and snippets.

@kolattukudy
Created August 7, 2020 03:40
Show Gist options
  • Save kolattukudy/1618e84f1606fd556d15a18b77027190 to your computer and use it in GitHub Desktop.
Save kolattukudy/1618e84f1606fd556d15a18b77027190 to your computer and use it in GitHub Desktop.
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