{"record":{"id":"d6431322579e6ecb","repo":"mikefarah/yq","slug":"v-expected-either-a-str-or-int-in-the-path","errorCode":null,"errorMessage":"%v: expected either a !!str or !!int in the path, found %v instead","messagePattern":"(.+?): expected either a !!str or !!int in the path, found (.+?) instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_path.go","lineNumber":35,"sourceCode":"func getPathArrayFromNode(funcName string, node *CandidateNode) ([]interface{}, error) {\n\tif node.Kind != SequenceNode {\n\t\treturn nil, fmt.Errorf(\"%v: expected path array, but got %v instead\", funcName, node.Tag)\n\t}\n\n\tpath := make([]interface{}, len(node.Content))\n\n\tfor i, childNode := range node.Content {\n\t\tswitch childNode.Tag {\n\t\tcase \"!!str\":\n\t\t\tpath[i] = childNode.Value\n\t\tcase \"!!int\":\n\t\t\tnumber, err := parseInt(childNode.Value)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"%v: could not parse %v as an int: %w\", funcName, childNode.Value, err)\n\t\t\t}\n\t\t\tpath[i] = number\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"%v: expected either a !!str or !!int in the path, found %v instead\", funcName, childNode.Tag)\n\t\t}\n\n\t}\n\treturn path, nil\n}\n\n// SETPATH(pathArray; value)\nfunc setPathOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tlog.Debugf(\"SetPath\")\n\n\tif expressionNode.RHS.Operation.OperationType != blockOpType {\n\t\treturn Context{}, fmt.Errorf(\"SETPATH must be given a block (;), got %v instead\", expressionNode.RHS.Operation.OperationType.Type)\n\t}\n\n\tlhsPathContext, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS.LHS)\n\n\tif err != nil {\n\t\treturn Context{}, err","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_path.go#L17-L53","documentation":"Every element of a SETPATH/DELPATHS path array must be either a string (map key) or an int (array index). getPathArrayFromNode throws this error, prefixed with the operator name, when an element has any other tag — typically !!float, !!bool, !!null, or !!map/!!seq elements nested inside a path array.","triggerScenarios":"'SETPATH([1.5]; v)' (float index), 'SETPATH([true]; v)', 'SETPATH([null]; v)', 'DELPATHS([[\"a\", [\"b\"]]])' (nested array as path element), or a path expression yielding map entries.","commonSituations":"Computed indices producing floats (division), keys that are null because the document lacks expected fields, accidentally passing data structures as paths instead of key strings, jq-style paths copied over that use floats.","solutions":["Convert float indices to ints: '(.idx | floor | tonumber)' or fix division to integer arithmetic","Coerce non-string keys to strings: '(.k | tostring)' inside the path array","Ensure the path array contains only string keys and int indices, e.g. 'SETPATH([\"a\", 0]; v)'"],"exampleFix":"// before\nyq 'SETPATH([.i / 2]; \"x\")' f.yml   // 1/2 -> 0.5 !!float\n// after\nyq 'SETPATH([.i / 2 | floor]; \"x\")' f.yml","handlingStrategy":"validation","validationCode":"yq '[.path[] | tag] | all(. == \"!!str\" or . == \"!!int\")' f.yml  # must be true","typeGuard":"yq 'select([.path[] | tag] | all(. == \"!!str\" or . == \"!!int\"))' f.yml","tryCatchPattern":"// shell\nout=$(yq 'SETPATH([.i / 2]; v)' f.yml 2>&1) || { echo \"bad path element: $out\"; exit 1; }","preventionTips":["Floor/tonumber float indices before use","tostring non-string keys","Keep path arrays to strings and ints only"],"tags":["yq","setpath","delpaths","path-expression","type-mismatch"],"backgroundTag":"invalid-path-expression","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"}