{"record":{"id":"38790cc42554257b","repo":"mikefarah/yq","slug":"from-entries-only-runs-against-arrays","errorCode":null,"errorMessage":"from entries only runs against arrays","messagePattern":"from entries only runs against arrays","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_entries.go","lineNumber":118,"sourceCode":"\tnode.Kind = MappingNode\n\tnode.Tag = \"!!map\"\n\treturn node, nil\n}\n\nfunc fromEntriesOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {\n\tvar results = list.New()\n\tfor el := context.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tcandidate := el.Value.(*CandidateNode)\n\n\t\tswitch candidate.Kind {\n\t\tcase SequenceNode:\n\t\t\tmapResult, err := fromEntries(candidate)\n\t\t\tif err != nil {\n\t\t\t\treturn Context{}, err\n\t\t\t}\n\t\t\tresults.PushBack(mapResult)\n\t\tdefault:\n\t\t\treturn Context{}, fmt.Errorf(\"from entries only runs against arrays\")\n\t\t}\n\t}\n\n\treturn context.ChildContext(results), nil\n}\n\nfunc withEntriesOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\n\t//to_entries on the context\n\ttoEntries, err := toEntriesOperator(d, context, expressionNode)\n\tif err != nil {\n\t\treturn Context{}, err\n\t}\n\n\tvar results = list.New()\n\n\tfor el := toEntries.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tcandidate := el.Value.(*CandidateNode)","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_entries.go#L100-L136","documentation":"The `from_entries` operator converts an array of {key, value} objects into a map. It only accepts SequenceNode inputs; when a candidate document node is any other kind (map, scalar, null), fromEntriesOperator returns this error. It exists to stop users from applying an array-only transform to non-array data.","triggerScenarios":"Calling `from_entries` directly on an object (e.g. `{a: 1} | from_entries`), on a scalar, or when the piped input is null/empty rather than an array of entry objects.","commonSituations":"Users confuse from_entries with to_entries and apply it to a map; a previous expression unexpectedly yields a scalar; reading a top-level JSON object and trying to convert it to entries.","solutions":["Pipe the input through to_entries first if you have a map: `. | to_entries | ... | from_entries`","Wrap scalars into an array context or correct the expression so input is an array","Check for null input (empty file/missing key) and provide a default: `. // [] | from_entries`","Use map_values/map instead if the intent was transforming a map, not rebuilding one"],"exampleFix":"// before\n{\"a\": 1} | from_entries\n// error: from entries only runs against arrays\n\n// after\n{\"a\": 1} | to_entries | from_entries","handlingStrategy":"type-guard","validationCode":"yq 'select(kind == \"seq\") // empty' input.yaml","typeGuard":"def is_array_node(node):\n    return node is not None and getattr(node, 'kind', None) == 'seq'","tryCatchPattern":"if ! out=$(yq 'from_entries' file.yaml 2>&1); then\n  echo \"from_entries needs an array input: $out\" >&2\nfi","preventionTips":["Pipe maps through to_entries before from_entries","Check node kind with kind == \"seq\" in the expression","Default empty/missing inputs to []"],"tags":["yq","entries","type-mismatch"],"backgroundTag":"operator-requires-array-input","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}