Groovy web console

subscribe to the feed Subscribe
to this
Json2Json Transformation (via #groovywebconsole)
tweet this snippet Tweet

Json2Json Transformation

Published 11 months ago by Kiran Patel with tags JsonBuilder Json2json
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonBuilder

def response = """[   {
      "name": "John",
      "online_status": "online"
      "name": "Marry",
      "online_status": "online"

def json = new groovy.json.JsonSlurper().parseText(response)

def json1 = new JsonBuilder()

json1 {   
    def array = []
    json.each{ item -> 
        array.add({  n
            s item.online_status
    k array

println json1.toString()