I need to export JSON in csv file. how to add values to each column? I know how to add rows. Here's an example code:
def data = [
['place', 'firstname', 'lastname', 'team'],
['1', 'Lorena', 'Wiebes', 'Team DSM'],
['2', 'Marianne', 'Vos', 'Team Jumbo Visma'],
['3', 'Lotte', 'Kopecky', 'Team SD Worx']
]
def file = new File("C:/Temp/data.csv")
file.text = data*.join(',').join(System.lineSeparator())
Result:
I need result:
Please suggest good literature on Groovy with examples, thank you.
def data = [
['place', 'firstname', 'lastname', 'team'],
['1', 'Lorena', 'Wiebes', 'Team DSM'],
['2', 'Marianne', 'Vos', 'Team Jumbo Visma'],
['3', 'Lotte', 'Kopecky', 'Team SD Worx']
]
def file = new File("C:/Temp/data.csv")
def stringBuilder = new StringBuilder()
data.each { row ->
stringBuilder.append(row.join(';')).append(System.lineSeparator())
}
file.text = stringBuilder.toString()