Groovy web console

subscribe to the feed Subscribe
to this
site
test (via #groovywebconsole)
tweet this snippet Tweet
this
script

test

Published 2 months ago by bn_work with tags JsonSlurper
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonSlurper;

def jsonSlurper = new JsonSlurper();

t = '''\
{
    "statusCode": 200,
    "headers": {},
    "pageInfo": {
        "startIndex": 0,
        "resultCount": 2,
        "totalResults": 0
    },
    "resources": [
        {
            "name": "test1",
            "attributes": {
                "RESTFUL_REQUESTS": "[]"
            },
            "type": {
                "id": "c49de703-d5ef-11e8-a741-bb9299a5a959",
                "name": "type1 repository"
            },
            "host": "https://host1.domain.net/",
            "authentication": {}
        },
        {
            "name": "test2",
            "attributes": {
                "RESTFUL_REQUESTS": "[]"
            },
            "type": {
                "id": "c59de703-d5ef-11e8-a741-bb9299a5a959",
                "name": "type2 repository"
            },
            "host": "https://host2.domain.net/",
            "authentication": {}
        }
   ]
}''';

println jsonSlurper.parseText(t).resources*.name.toString();