{"record":{"id":"9be18e30d5e88021","repo":"kubernetes/kops","slug":"unable-to-marshal-json-v","errorCode":null,"errorMessage":"unable to marshal JSON: %v","messagePattern":"unable to marshal JSON: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_assets.go","lineNumber":169,"sourceCode":"\n\tswitch options.Output {\n\tcase OutputTable:\n\t\tif err = imageOutputTable(result.Images, out); err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn fileOutputTable(result.Files, out)\n\tcase OutputYaml:\n\t\ty, err := yaml.Marshal(result)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to marshal YAML: %v\", err)\n\t\t}\n\t\tif _, err := out.Write(y); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to output: %v\", err)\n\t\t}\n\tcase OutputJSON:\n\t\tj, err := json.Marshal(result)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to marshal JSON: %v\", err)\n\t\t}\n\t\tif _, err := out.Write(j); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to output: %v\", err)\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported output format: %q\", options.Output)\n\t}\n\n\treturn nil\n}\n\nfunc imageOutputTable(images []*Image, out io.Writer) error {\n\tfmt.Println(\"\")\n\tt := &tables.Table{}\n\tt.AddColumn(\"CANONICAL\", func(i *Image) string {\n\t\treturn i.Canonical\n\t})\n\tt.AddColumn(\"DOWNLOAD\", func(i *Image) string {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_assets.go#L151-L187","documentation":"RunGetAssets uses encoding/json.Marshal on the AssetResult for `kops get assets -o json` and wraps marshal failures with this message. AssetResult contains only pointer-to-struct slices of strings, so failures typically indicate a programming/data error rather than user misconfiguration.","triggerScenarios":"`kops get assets -o json` where json.Marshal(result) errors — practically only possible if the result structure contains unsupported types (channels, funcs, cycles) as in modified builds.","commonSituations":"Custom/patched kops builds with new AssetResult fields of unmarshalable types; nil map/interface oddities introduced by plugins or forks.","solutions":["Read the wrapped inner error to find the offending field","Ensure all AssetResult fields are JSON-marshalable (plain data types)","Retry with -o yaml or default table output to confirm the data itself is fine","Rebuild from upstream kops if running a patched binary"],"exampleFix":"// before\ntype AssetResult struct {\n    Images []*Image\n    Extra  chan string // unmarshalable\n}\n// after\ntype AssetResult struct {\n    Images []*Image `json:\"images,omitempty\"`\n    Extra  string   `json:\"extra,omitempty\"`\n}","handlingStrategy":"validation","validationCode":"// ensure result contains only JSON-marshalable data before calling\nif err := json.Valid(mustBytes(json.Marshal(result))); err != nil {\n    return fmt.Errorf(\"asset result not serializable\")\n}","typeGuard":null,"tryCatchPattern":"j, err := json.Marshal(result)\nif err != nil {\n    return fmt.Errorf(\"unable to marshal JSON: %v\", err)\n}","preventionTips":["Keep AssetResult fields limited to plain data types (string, slices)","Avoid adding channels/funcs/cyclic structures to result structs","Add unit tests that marshal AssetResult","Prefer upstream kops over patched builds"],"tags":["json","serialization","assets","cli"],"backgroundTag":"json-marshal-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}