{"record":{"id":"c4c8291317e12b33","repo":"mikefarah/yq","slug":"can-only-pivot-elements-of-seq-or-map-types-r","errorCode":null,"errorMessage":"can only pivot elements of !!seq or !!map types, received %v","messagePattern":"can only pivot elements of !!seq or !!map types, received (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_pivot.go","lineNumber":116,"sourceCode":"\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}\n","sourceCodeStart":98,"sourceCodeEnd":122,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_pivot.go#L98-L122","documentation":"After confirming the candidate is a sequence, pivot inspects the common element tag: elements must themselves be sequences or maps to be pivoted. If the unique element tag is anything else (e.g. all scalars), this error is thrown. yq cannot pivot flat scalar lists because there is no key/structure to pivot on.","triggerScenarios":"`yq '[1, 2, 3] | pivot(.)'` — a sequence of scalars; a sequence whose elements are all strings or numbers.","commonSituations":"Trying to pivot a flat list of values instead of objects/arrays; missing a mapping step that should wrap scalars into objects; loading data where records degenerated to scalars.","solutions":["Pivot sequences of maps or sequences only: `[{k: 1}, {k: 2}] | pivot(.k)`.","Wrap scalars into objects first, e.g. `map({value: .}) | pivot(.value)`.","If you intended a different transformation on scalar lists, use `group_by`, `sort`, or `reverse` instead of pivot.","Check element tags with `[.[] | tag] | unique` before pivoting."],"exampleFix":"// before\nyq '[1, 2, 3] | pivot(.)' file.yml\n// after\nyq '[1, 2, 3] | map({value: .}) | pivot(.value)' file.yml","handlingStrategy":"validation","validationCode":"yq -e 'tag == \"!!seq\" and ([.[] | tag] | unique | . == [\"!!map\"] or . == [\"!!seq\"])' <<< \"$seq\" || echo \"pivot elements must all be maps or all sequences\"","typeGuard":"isPivotable() { [ \"$(yq '[.[] | tag] | unique | ( . == [\"!!map\"] or . == [\"!!seq\"] )' <<< \"$1\")\" = \"true\" ]; }","tryCatchPattern":"out=$(yq 'pivot(.k)' file.yml 2>&1) || { echo \"$out\"; echo \"scalar lists need wrapping: map({value: .})\"; }","preventionTips":["Pivot only lists of objects or lists — never flat scalar lists.","Wrap scalars first: map({value: .}).","Verify element tags before pivoting.","Consider group_by/sort for flat-list transformations instead of pivot."],"tags":["yq","pivot","scalar-elements","unsupported-type"],"backgroundTag":"pivot-unsupported-element-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"}