The params key of the JSON object is associated with the JSON object, not the array, so you cannot access it by index. JsonSlurper maps JSON objects to Groovy Maps, so you can access params its keys, which are strings, for example. dalist.params.grommet , which will give you a map [name: 'x', data: 'y'] .
To access the params keys, you can do dalist.params.keySet() , which will give you a list of ['grommet', 'widget'] . If you are only interested in knowing params keys, this should do the trick. If you need to get the string 'grommet' for some reason, you can do this by referring to the first element of this list, i.e. dalist.params.keySet()[0] , but I donβt know why you would like to know. And I'm not sure if the first key of this card is always guaranteed to be 'grommet' , since JSON objects are unordered by specification (from json.org : the object is an unordered set of name / value pairs), but Groovy cards are in turn ordered (the default implementation is LinkedHashMap) ... so I would suggest that the order is preserved when parsing JSON in the Groovy world, but I would try not to rely on this particular hehe behavior.
epidemian
source share