mikefarah/yq · error
csv encoding only works for arrays of scalars (string/number
Error message
csv encoding only works for arrays of scalars (string/numbers/booleans), child[%v] is a %v
What it means
encodeRow, which flattens one array row into CSV columns, found a child that is not a ScalarNode (e.g. a nested map or array at child index %v). CSV rows are flat: every element of each array must be a string, number, or boolean; nested structures cannot be represented as a single CSV cell.
Source
Thrown at pkg/yqlib/encoder_csv.go:37
func (e *csvEncoder) CanHandleAliases() bool {
return false
}
func (e *csvEncoder) PrintDocumentSeparator(_ io.Writer) error {
return nil
}
func (e *csvEncoder) PrintLeadingContent(_ io.Writer, _ string) error {
return nil
}
func (e *csvEncoder) encodeRow(csvWriter *csv.Writer, contents []*CandidateNode) error {
stringValues := make([]string, len(contents))
for i, child := range contents {
if child.Kind != ScalarNode {
return fmt.Errorf("csv encoding only works for arrays of scalars (string/numbers/booleans), child[%v] is a %v", i, child.Tag)
}
stringValues[i] = child.Value
}
return csvWriter.Write(stringValues)
}
func (e *csvEncoder) encodeArrays(csvWriter *csv.Writer, content []*CandidateNode) error {
for i, child := range content {
if child.Kind != SequenceNode {
return fmt.Errorf("csv encoding only works for arrays of scalars (string/numbers/booleans), child[%v] is a %v", i, child.Tag)
}
err := e.encodeRow(csvWriter, child.Content)
if err != nil {
return err
}
}
return nilView on GitHub (pinned to 8b5af0694b)
Solutions
- Flatten nested structures before encoding (e.g. using [.[] | ... ] or flatten)
- Convert the nested value to a string with tostring
- Use a hierarchical format (@json/@yaml) instead of @csv if nesting must be preserved
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at pkg/yqlib/encoder_csv.go:37 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/60a11b2dcf9780b3.
Report an issue: GitHub.