{"record":{"id":"a4a20ed75e0e8d64","repo":"mikefarah/yq","slug":"cannot-index-array-with-v","errorCode":null,"errorMessage":"cannot index array with %v","messagePattern":"cannot index array with (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_pick.go","lineNumber":34,"sourceCode":"\t\t\tclonedKey := original.Content[indexInMap].Copy()\n\t\t\tclonedValue := original.Content[indexInMap+1].Copy()\n\t\t\tfilteredContent = append(filteredContent, clonedKey, clonedValue)\n\t\t}\n\t}\n\n\tnewNode := original.CopyWithoutContent()\n\tnewNode.AddChildren(filteredContent)\n\n\treturn newNode\n}\n\nfunc pickSequence(original *CandidateNode, indices *CandidateNode) (*CandidateNode, error) {\n\n\tfilteredContent := make([]*CandidateNode, 0)\n\tfor index := 0; index < len(indices.Content); index = index + 1 {\n\t\tindexInArray, err := parseInt(indices.Content[index].Value)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"cannot index array with %v\", indices.Content[index].Value)\n\t\t}\n\n\t\tif indexInArray > -1 && indexInArray < len(original.Content) {\n\t\t\tfilteredContent = append(filteredContent, original.Content[indexInArray].Copy())\n\t\t}\n\t}\n\n\tnewNode := original.CopyWithoutContent()\n\tnewNode.AddChildren(filteredContent)\n\n\treturn newNode, nil\n}\n\nfunc pickOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tlog.Debugf(\"Pick\")\n\n\tcontextIndicesToPick, err := d.GetMatchingNodes(context, expressionNode.RHS)\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_pick.go#L16-L52","documentation":"When `pick` is applied to an array, every entry of the indices array must parse as an integer, because array indices must be numeric. This error is thrown when `parseInt` fails on an index value (e.g. a string like \"abc\" or \"1.5\"). It prevents silently picking nothing or corrupting index semantics.","triggerScenarios":"`yq 'pick([\"a\", \"b\"])'` on an array document, or `pick([0, \"x\"])` where a non-integer string appears in the indices sequence. Also occurs when the indices come from data containing non-integer scalars.","commonSituations":"Reusing a map-key pick expression on an array; indices built from string data; typos such as `pick([1o])` or values with whitespace/floats from computed expressions.","solutions":["Use integer indices when picking from arrays: `pick([0, 2])`.","Check each index value parses as an int; convert with `tonumber` style expressions if derived from strings.","If picking by key, ensure the node is a map — use `select(tag == \"!!map\")` or a different operator.","Trim/format computed index expressions to avoid floats like `1.0`."],"exampleFix":"// before\nyq 'pick([\"a\", \"b\"])' file.json   # on an array\n// after\nyq 'pick([0, 1])' file.json","handlingStrategy":"validation","validationCode":"yq -e 'map(tag == \"!!int\") | all' <<< \"$indices\" || echo \"pick indices must all be integers\"","typeGuard":"isIntArray() { [ \"$(yq 'map(tag == \"!!int\") | all' <<< \"$1\")\" = \"true\" ]; }","tryCatchPattern":"out=$(yq 'pick($idx)' file.yml 2>&1) || { echo \"$out\"; echo \"pick on arrays requires integer indices\"; }","preventionTips":["Use numeric indices for arrays and string keys only for maps.","Convert computed indices to integers before passing to pick.","Validate indices with map(tag == \"!!int\") | all.","Double-check whether the target node is an array (indices) or map (keys)."],"tags":["yq","pick","array-index","parse-error"],"backgroundTag":"invalid-array-index","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"}