1 | initial version |
To create a list of objects in Groovy from Json, you can use the JsonSlurper class. Here is an example code:
import groovy.json.JsonSlurper
def jsonString = '''[{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]'''
def jsonSlurper = new JsonSlurper()
List<Map<String,Object>> objectList = jsonSlurper.parseText(jsonString)
println objectList
In this example, we use the JsonSlurper
class to parse the Json string into a list of maps (List<Map<String,Object>>
). Each map represents an object in the Json array. We then print the list for verification.