mikefarah/yq · error
expected to find one 'value' entry but found %v in position
Error message
expected to find one 'value' entry but found %v in position %v
What it means
yq's `to_entries`-related entry parsing (parseEntry) converts a {key, value} object into a key/value pair. After traversing the candidate's `value` key it expects exactly one matching node. If the object has zero or multiple `value` entries (e.g. a malformed or multi-value entry object), the operator cannot form a single entry and fails. This is a validation error thrown while building maps from entries, typically via `with_entries`/`from_entries` input that isn't a proper {key, value} map.
Source
Thrown at pkg/yqlib/operator_entries.go:80
}
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.Content
for index := 0; index < len(contents); index = index + 1 {
key, value, err := parseEntry(contents[index], index)
if err != nil {
return nil, err
}
node.AddKeyValueChild(key, value)View on GitHub (pinned to 8b5af0694b)
Solutions
- Ensure each array element is an object with exactly one `key` and one `value` entry before using from_entries/with_entries
- Transform mismatched fields first, e.g. `.[] |= {key: .name, value: .val}` before from_entries
- Filter out malformed elements with map(select(has("value")))
- If using a different key name, rename it to `value` upstream
Example fix
// before
[{key: "a"}] | from_entries
// error: expected to find one 'value' entry but found 0 in position 0
// after
[{key: "a", value: 1}] | from_entries Defensive patterns
Strategy: validation
Validate before calling
# ensure every element has exactly one key and one value
yq '[.[] | select(has("key") and has("value"))] | all(. == true)' entries.yaml Type guard
def is_entry(o):
return isinstance(o, dict) and "key" in o and "value" in o Try / catch
out=$(yq 'from_entries' in.yaml 2>&1) || {
echo "malformed entry objects: $out" >&2
exit 1
} Prevention
- Always generate entry objects as {key: ..., value: ...}
- Run to_entries before editing so structure stays canonical
- Validate with has("key") and has("value") before from_entries
When it happens
Trigger: Running `with_entries` or `from_entries` over an array whose elements are maps that lack a `value` key, or whose `value` key traversal returns more than one result (e.g. via unusual node content or aliases).
Common situations: Users feed objects missing `value` (only `{key: x}`) into from_entries; documents built by other tools contain entry-like objects with extra/multiple value fields; keys spelled differently (`name`/`val`) are passed in expecting from_entries to accept them.
Related errors
- from entries only runs against arrays
- cannot repeat string by a negative number (%v)
- system operator: command must be a non-empty string
- cannot convert node value [%v] at path %v of tag %v to numbe
- no support for input format
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/89e7e6e98a91b9ba.
Report an issue: GitHub.