Groovy web console

subscribe to the feed Subscribe
to this
site

Untitled

Published 3 weeks ago by Anonymous
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
    import groovy.json.*    
    def json_req = '''{
    "date":"Tue, 06 Oct 2015 09:10:52 GMT",
    "nonce": "6cm7PmwDOKs",
    "devId": "<value>",
    "appId": "<value>",
    "tags": []
    }'''
    
    def json = new JsonSlurper().parseText(json_req)
    println json.getClass().getName()
    String tag = "@TestExe-124"
    def builder = new JsonBuilder()
    def newTag= builder{
       "name" tag
        "type" "Tag"
        "location" {
            "line" 3
            "column" 5
        }
    }
    def newTag2= builder{"name" tag}
    json.tags += newTag
    json.tags += newTag2
    //json.tags += new JsonBuilder(){"name" tag}
    //json.tags += new JsonBuilder(){"name" tag
    //    "type" "Tag"
    //   "location" {
    //        "line" 1
    //        "column" 1
    //    }
    //}
    json.put('sig', 'Kamil')
    println new JsonBuilder(json).toPrettyString()