mikefarah/yq · error
expected to find one 'key' entry but found %v in position %v
Error message
expected to find one 'key' entry but found %v in position %v
What it means
fromEntries→parseEntry traverses each entry map for its 'key' field with auto-creation disabled, and expects exactly one result. The traversal returned a different count (%v) for the entry at position %v — usually the entry is missing 'key' entirely, or contains a nested 'key' collection producing multiple matches.
Source
Thrown at pkg/yqlib/operator_entries.go:72
default:
if candidate.Tag != "!!null" {
return Context{}, fmt.Errorf("%v has no keys", candidate.Tag)
}
}
}
return context.ChildContext(results), nil
}
func parseEntry(candidateNode *CandidateNode, position int) (*CandidateNode, *CandidateNode, error) {
prefs := traversePreferences{DontAutoCreate: true}
keyResults, err := traverseMap(Context{}, candidateNode, createStringScalarNode("key"), prefs, false)
if err != nil {
return nil, nil, err
} else if keyResults.Len() != 1 {
return nil, nil, fmt.Errorf("expected to find one 'key' entry but found %v in position %v", keyResults.Len(), position)
}
valueResults, err := traverseMap(Context{}, candidateNode, createStringScalarNode("value"), prefs, false)
if err != nil {
return nil, nil, err
} else if valueResults.Len() != 1 {
return nil, nil, fmt.Errorf("expected to find one 'value' entry but found %v in position %v", valueResults.Len(), position)
}
return keyResults.Front().Value.(*CandidateNode), valueResults.Front().Value.(*CandidateNode), nil
}
func fromEntries(candidateNode *CandidateNode) (*CandidateNode, error) {
var node = candidateNode.CopyWithoutContent()
var contents = candidateNode.ContentView on GitHub (pinned to 8b5af0694b)
Solutions
- Ensure every entry from to_entries keeps both 'key' and 'value' fields
- Do not drop or rename 'key' when transforming entries before from_entries
- Guard: entries | map(select(has("key"))) | from_entries
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pkg/yqlib/operator_entries.go:72 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/61303f9ab0b581ba.
Report an issue: GitHub.