{"record":{"id":"10e5d7384a534f7b","repo":"mikefarah/yq","slug":"cannot-pivot-node-of-type-v","errorCode":null,"errorMessage":"cannot pivot node of type %v","messagePattern":"cannot pivot node of type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_pivot.go","lineNumber":103,"sourceCode":"\t}\n\tresult := CandidateNode{Kind: MappingNode}\n\tfor _, k := range keys {\n\t\tpivotRow := CandidateNode{Kind: SequenceNode}\n\t\tpivotRow.AddChildren(\n\t\t\tpad(m[k], sz, nullNodeFactory))\n\t\tresult.AddKeyValueChild(createScalarNode(k, k), &pivotRow)\n\t}\n\treturn &result\n}\n\nfunc pivotOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {\n\tlog.Debug(\"Pivot\")\n\tresults := list.New()\n\n\tfor el := context.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tcandidate := el.Value.(*CandidateNode)\n\t\tif candidate.Tag != \"!!seq\" {\n\t\t\treturn Context{}, fmt.Errorf(\"cannot pivot node of type %v\", candidate.Tag)\n\t\t}\n\t\ttag, err := getUniqueElementTag(candidate)\n\t\tif err != nil {\n\t\t\treturn Context{}, err\n\t\t}\n\t\tvar pivot *CandidateNode\n\t\tswitch tag {\n\t\tcase \"!!seq\":\n\t\t\tpivot = pivotSequences(candidate)\n\t\tcase \"!!map\":\n\t\t\tpivot = pivotMaps(candidate)\n\t\tdefault:\n\t\t\treturn Context{}, fmt.Errorf(\"can only pivot elements of !!seq or !!map types, received %v\", tag)\n\t\t}\n\t\tresults.PushBack(pivot)\n\t}\n\treturn context.ChildContext(results), nil\n}","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_pivot.go#L85-L121","documentation":"`pivot` is only defined on sequence nodes; this top-level check rejects any candidate whose tag is not `!!seq`. The error names the actual tag so you can see whether you applied pivot to a map, scalar or other node.","triggerScenarios":"Running `yq 'pivot(.a)'` where the selected node is a map or scalar instead of an array; applying pivot at the root of an object document.","commonSituations":"Misremembering pivot as working on maps directly; selecting the wrong key (the container object rather than its array field); schema drift where a field changed from array to object.","solutions":["Select the array field first: `.rows | pivot(.x)` instead of `. | pivot(.x)` when root is a map.","Verify the target is an array with `tag` before pivoting.","If the data is a map, convert or extract its values into a sequence first (e.g. `.[]` / `to_entries`).","Check the reported tag in the message and adjust the path expression."],"exampleFix":"// before\nyq 'pivot(.id)' file.yml      # root is a map\n// after\nyq '.items | pivot(.id)' file.yml","handlingStrategy":"type-guard","validationCode":"yq -e 'tag == \"!!seq\"' <<< \"$node\" || echo \"pivot requires an array\"","typeGuard":"isSeq() { [ \"$(yq 'tag == \"!!seq\"' <<< \"$1\")\" = \"true\" ]; }","tryCatchPattern":"out=$(yq '.items | pivot(.id)' file.yml 2>&1) || { echo \"$out\"; echo \"pivot only works on arrays — select the array field first\"; }","preventionTips":["Always select the array field before pivot, not its parent object.","Check the target's tag with yq 'tag' before pivoting.","For maps, extract values into a sequence first.","Watch for schema drift where array fields become objects."],"tags":["yq","pivot","type-mismatch","node-kind"],"backgroundTag":"pivot-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"}