mikefarah/yq · error
unsupported node kind for TOML: %v
Error message
unsupported node kind for TOML: %v
What it means
Inside encodeTopLevelEntry, the switch over node Kind handles scalar, sequence (incl. array-of-tables), and mapping (incl. inline tables); any other Kind falls through to 'unsupported node kind for TOML: %v'. This guards against kinds TOML cannot represent at a top-level entry position.
Source
Thrown at pkg/yqlib/encoder_toml.go:213
return err
}
}
return nil
}
// Regular array attribute
return te.writeArrayAttribute(w, path[len(path)-1], node)
case MappingNode:
// Use inline table syntax only for nodes explicitly marked as TOML inline tables.
// YAML flow-style mappings are not treated as inline tables; the FlowStyle attribute
// is a YAML-specific rendering hint and should not affect TOML output. This ensures
// that auto-detected JSON input (parsed as YAML flow style) produces readable table
// sections, consistent with explicitly parsed JSON input.
if node.EncodeHint == EncodeHintInline {
return te.writeInlineTableAttribute(w, path[len(path)-1], node)
}
return te.encodeSeparateMapping(w, path, node)
default:
return fmt.Errorf("unsupported node kind for TOML: %v", node.Kind)
}
}
func isTomlArrayOfTables(seq *CandidateNode) bool {
if len(seq.Content) == 0 {
return false
}
for _, it := range seq.Content {
if it.Kind != MappingNode || it.EncodeHint == EncodeHintInline {
return false
}
}
return true
}
func isTomlAttribute(node *CandidateNode) bool {
if node.Kind == ScalarNode {
return trueView on GitHub (pinned to 8b5af0694b)
Solutions
- Resolve aliases before encoding: `yq -o toml '(.[] | select(is("alias"))) |= eval'` or avoid anchors in the source.
- Flatten/simplify the expression so values are plain scalars, maps, or sequences.
- Preview with `-o json` to identify the offending node and normalize it (e.g. with `.|= .` dereferencing or rebuilding).
- Upgrade yq — alias handling in the TOML encoder has improved over releases.
Example fix
# before yq -o toml '.' doc.yaml # value is an alias node -> unsupported kind # after yq -o toml '(.. | select(kind == "alias")) |= eval' doc.yaml
Defensive patterns
Strategy: type-guard
Validate before calling
yq '[.. | kind] | unique' file.yaml # look for 'alias' or unexpected kinds before -o toml
Type guard
hasAlias() { yq -e '[.. | kind] | any(. == "alias")' "$1" > /dev/null; } Try / catch
yq -o toml '.' doc.yaml 2>/dev/null || yq -o toml '(.. | select(kind == "alias")) |= eval' doc.yaml
Prevention
- Resolve anchors/aliases before TOML encoding
- Ensure values at root entries are scalar/map/seq only
- Preview kinds with the `kind` operator before encoding
When it happens
Trigger: A root mapping whose value node has a non-scalar/seq/map Kind (typically an unresolved AliasNode or document/fragment node) is encoded with `-o toml`, falling into the default branch at encoder_toml.go:213.
Common situations: YAML anchors/aliases not resolved before TOML encoding; synthetic nodes built by expressions that keep document kinds; hand-built CandidateNodes via the library API.
Related errors
- TOML encoder expects a mapping at the root level
- INI encoder supports only MappingNode at the root level, got
- unsupported node %v
- unsupported node %v
- cannot encode TOML entry with empty path
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/653cd5f891e9314e.
Report an issue: GitHub.