Delete brackets for a jsonslurper value

Hello, i got the following issue:
I am getting and error storing my value on a global variable, i added the jsonslurper, and is storing my value, but with brackets, how i can delete the brackets?
Here is my code:

res1 = WS.sendRequest(findTestObject('API/Users, Companies, Groups/Groups/CREATE GROUP'))
WS.verifyResponseStatusCode(res1, 200)
def slurper = new groovy.json.JsonSlurper()
def result = slurper.parseText(res1.getResponseBodyContent())
def value = result.id
println('the value is: ' + value)
GlobalVariable.TestData = value
println('test data is: ' + GlobalVariable.TestData)

this is the console result:

i dont need the brackets: [id] what i need is only the id, so i can use it on another test

Try this

println(result["id"])

you don’t have to ‘delete the brackets’. jsonSlurper will return the data as a groovy collection so you have to learn how to work with lists, maps and so on:
http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html

since you didn’t posted a sample json response, i can only guess that the ‘id’ field is an array, so you have to pick a given element from the parsed response, e.g:

def value = result.id[0]

to check the type of an arbitrary object in your code, you can simply do an:

println obj.getClass()

that can save you from a lot of headaches

Thank you, that works for me!

2 Likes