Groovy web console

subscribe to the feed Subscribe
to this
site

Untitled

Published 1 month 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": [
                    {
                        "name": "@Indywidualny"
                    },
                    {
                        "name": "@MiniFirma"
                    },
                    {
                        "name": "@MF+"
                    }
                ]
    }'''
    
    def json = new JsonSlurper().parseText(json_req)
    println json.getClass().getName()
    String tag = "@TestExe-1234"
    //def builder = new JsonBuilder()
    //def newTag= builder{"name" tag}
    //json.tags += newTag
    json.tags += new JsonBuilder(){"name" tag}
    json.put('sig', 'Kamil')
    println new JsonBuilder(json).toPrettyString()