This Commented CUE
demonstrates how to use the built-in function
encoding/csv.Decode
to decode a file containing comma-separated values (CSV) into a list of lists.
data.csv
Id,Name,Location,Species
1,Charlie,"Ripon, North Yorkshire",cat
2,Fred,San Francisco,cat
3,Greyfriars Bobby,Edinburgh,dog
4,Nemo,???,fish
file.cue
package example
import "encoding/csv"
input: string
output: csv.Decode(input)
TERMINAL
$ cue export file.cue -l input: text: data.csv -e output
[
[
"Id",
"Name",
"Location",
"Species"
],
[
"1",
"Charlie",
"Ripon, North Yorkshire",
"cat"
],
[
"2",
"Fred",
"San Francisco",
"cat"
],
[
"3",
"Greyfriars Bobby",
"Edinburgh",
"dog"
],
[
"4",
"Nemo",
"???",
"fish"
]
]
Related content
- The
encoding/csv
built-in package