{"record":{"id":"109ff878a8294c4d","repo":"mikefarah/yq","slug":"cannot-pick-indices-from-type-v-v","errorCode":null,"errorMessage":"cannot pick indices from type %v (%v)","messagePattern":"cannot pick indices from type (.+?) \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_pick.go","lineNumber":77,"sourceCode":"\t}\n\n\tvar results = list.New()\n\n\tfor el := context.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tnode := el.Value.(*CandidateNode)\n\n\t\tvar replacement *CandidateNode\n\t\tswitch node.Kind {\n\t\tcase MappingNode:\n\t\t\treplacement = pickMap(node, indicesToPick)\n\t\tcase SequenceNode:\n\t\t\treplacement, err = pickSequence(node, indicesToPick)\n\t\t\tif err != nil {\n\t\t\t\treturn Context{}, err\n\t\t\t}\n\n\t\tdefault:\n\t\t\treturn Context{}, fmt.Errorf(\"cannot pick indices from type %v (%v)\", node.Tag, node.GetNicePath())\n\t\t}\n\n\t\treplacement.LeadingContent = node.LeadingContent\n\t\tresults.PushBack(replacement)\n\t}\n\n\treturn context.ChildContext(results), nil\n}\n","sourceCodeStart":59,"sourceCodeEnd":86,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_pick.go#L59-L86","documentation":"`pick` with an array of indices can only be applied to sequence (array) nodes; applying it to a scalar, map or other kind hits this default branch. The message reports the node's tag and nice path so you can locate the offending node. yq throws it rather than guessing how to index a non-array by position.","triggerScenarios":"Running `yq 'pick([0,1])'` on a document whose root (or selected nodes) are scalars or maps; a `pick` traversal that matches mixed-type nodes where at least one is not a sequence.","commonSituations":"Pointing pick at the wrong level of nesting (map instead of array); documents whose schema changed between versions; applying an array-oriented expression to every document in a multi-doc stream where one doc is a scalar.","solutions":["Select the array before picking: `.myArray | pick([0,1])` instead of `.myArray | pick(...)` on the parent map.","Use map-key picking for maps (`pick([\"key1\"])`) and index picking only for arrays.","Guard with `select(tag == \"!!seq\") | pick([0,1])` to skip non-array nodes.","Inspect the path in the message and fix the traversal depth."],"exampleFix":"// before\nyq 'pick([0, 1])' file.yml            # root is a map\n// after\nyq '.items | pick([0, 1])' file.yml","handlingStrategy":"type-guard","validationCode":"yq -e 'tag == \"!!seq\"' <<< \"$node\" || echo \"pick([...]) requires an array\"","typeGuard":"isSeq() { [ \"$(yq 'tag == \"!!seq\"' <<< \"$1\")\" = \"true\" ]; }","tryCatchPattern":"out=$(yq 'select(tag == \"!!seq\") | pick([0,1])' file.yml 2>&1) || { echo \"$out\"; echo \"only arrays support index pick\"; }","preventionTips":["Pipe to the array field before picking: .items | pick([0,1]).","Use key-based pick (pick([\"a\"])) for maps.","Guard traversals with select(tag == \"!!seq\").","Use the path in the error message to fix traversal depth."],"tags":["yq","pick","type-mismatch","node-kind"],"backgroundTag":"pick-non-sequence-node","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"}