{"record":{"id":"9a3ef3913b43e760","repo":"mikefarah/yq","slug":"cannot-split-v-can-only-split-strings","errorCode":null,"errorMessage":"cannot split %v, can only split strings","messagePattern":"cannot split (.+?), can only split strings","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_strings.go","lineNumber":552,"sourceCode":"\n\trhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)\n\tif err != nil {\n\t\treturn Context{}, err\n\t}\n\tif rhs.MatchingNodes.Front() != nil {\n\t\tsplitStr = rhs.MatchingNodes.Front().Value.(*CandidateNode).Value\n\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\t\tif node.Tag == \"!!null\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tif node.guessTagFromCustomType() != \"!!str\" {\n\t\t\treturn Context{}, fmt.Errorf(\"cannot split %v, can only split strings\", node.Tag)\n\t\t}\n\t\tkind, tag, content := split(node.Value, splitStr)\n\t\tresult := node.CreateReplacement(kind, tag, \"\")\n\t\tresult.AddChildren(content)\n\t\tresults.PushBack(result)\n\t}\n\n\treturn context.ChildContext(results), nil\n}\n\nfunc split(value string, spltStr string) (Kind, string, []*CandidateNode) {\n\tvar contents []*CandidateNode\n\n\tif value != \"\" {\n\t\tlog.Debugf(\"going to spltStr[%v]\", spltStr)\n\t\tvar newStrings = strings.Split(value, spltStr)\n\t\tcontents = make([]*CandidateNode, len(newStrings))\n","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_strings.go#L534-L570","documentation":"The split operator ('split(sep)') in operator_strings.go only splits string nodes into arrays. Nodes tagged '!!null' are silently skipped, but any other non-string tag (int, bool, map, sequence) triggers this error, reporting the offending tag.","triggerScenarios":"Running '.a | split(\",\")' where .a is a number (e.g. 1234), boolean, array, or map; splitting a value read from YAML/JSON that YAML auto-typed to non-string; piping the result of a numeric expression like '.port | split(\".\")'.","commonSituations":"IPs/versions stored unquoted (192.168.0.1 parses as structure or string depending on quoting), so split fails on typed nodes; splitting numeric IDs; applying a string-split expression to a heterogeneous set of documents where some fields are null or numeric.","solutions":["Coerce to string before splitting: '.a |= (\"\\(. )\" | split(\",\"))' or use the string interpolation operator.","Quote the value at the source so YAML parses it as a string (e.g. version: \"1.2.3\").","Skip/filter non-string nodes first: 'select(tag == \"!!str\") | split(\",\")'."],"exampleFix":"// before (fails: .version parsed as something non-string)\nyq '.version | split(\".\")' chart.yaml\n\n// after\nyq '.version |= (\"\\(. )\" | split(\".\"))' chart.yaml","handlingStrategy":"type-guard","validationCode":"yq '.a | tag' file.yaml   # must be '!!str' before split\n// script check:\nTAG=$(yq '.a | tag' file.yaml); [ \"$TAG\" = \"!!str\" ] || echo \"split requires a string, got $TAG\"","typeGuard":"// in yq expression: select(tag == \"!!str\") | split(\",\")\nfunction isStringNode(node) { return node && node.tag === '!!str'; }","tryCatchPattern":"out=$(yq '.a | split(\",\")' file.yaml 2>&1) || { echo \"split failed: $out\"; out=\"$(yq '.a | (\"\\\\(.)\" | split(\",\"))' file.yaml)\"; }","preventionTips":["Coerce with string interpolation '\\\\(.)' before splitting values that may be typed.","Quote scalars in source YAML when they will be split (versions, IPs, CSV-ish fields).","Remember nulls are skipped silently — check for them if output array is unexpectedly empty."],"tags":["yq","split","type-mismatch","strings"],"backgroundTag":"split-requires-string-type","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"}