{"record":{"id":"709dc78c261bb6fb","repo":"kubernetes/kops","slug":"unable-to-marshal-json-v-709dc7","errorCode":null,"errorMessage":"unable to marshal JSON: %v","messagePattern":"unable to marshal JSON: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/validate_cluster.go","lineNumber":221,"sourceCode":"\t\t}\n\n\t\tswitch options.output {\n\t\tcase OutputTable:\n\t\t\tif err := validateClusterOutputTable(result, cluster, instanceGroups, out); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\tcase OutputYaml:\n\t\t\ty, err := yaml.Marshal(result)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unable to marshal YAML: %v\", err)\n\t\t\t}\n\t\t\tif _, err := out.Write(y); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error writing to output: %v\", err)\n\t\t\t}\n\t\tcase OutputJSON:\n\t\t\tj, err := json.Marshal(result)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unable to marshal JSON: %v\", err)\n\t\t\t}\n\t\t\tif _, err := out.Write(j); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error writing to output: %v\", err)\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unknown output format: %q\", options.output)\n\t\t}\n\n\t\tif len(result.Failures) == 0 {\n\t\t\tconsecutive++\n\t\t\tif consecutive < options.count {\n\t\t\t\tklog.Infof(\"(will retry): cluster passed validation %d consecutive times\", consecutive)\n\t\t\t\tif options.wait > 0 {\n\t\t\t\t\ttime.Sleep(options.interval)\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\treturn nil, fmt.Errorf(\"cluster passed validation %d consecutive times\", consecutive)\n\t\t\t\t}","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/validate_cluster.go#L203-L239","documentation":"This error is raised when json.Marshal(result) fails while rendering validation results in --output json mode. Like the YAML case, marshalling a fixed validation result struct should never fail; if it does, the result contains an unsupported value (func, channel, invalid UTF-8 in strings) and usually indicates a kops bug or version skew.","triggerScenarios":"`kops validate cluster -o json` where the result struct contains a value json.Marshal cannot encode (e.g. NaN via unsupported types, a func/channel field).","commonSituations":"Patched or mismatched kops binary producing a result struct with unsupported field types; custom validator injection; normally not user-triggerable.","solutions":["Re-run with default table output or -o yaml to still obtain results.","Verify official kops binary and matching cluster version; rebuild/upgrade if patched.","File a kops bug with the printed %v cause if it reproduces with official binaries."],"exampleFix":"// before\nkops validate cluster -o json\n// after\nkops validate cluster -o yaml","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"result, err := runValidateCluster(ctx, options)\nif err != nil && strings.Contains(err.Error(), \"unable to marshal JSON\") {\n\treturn runValidateCluster(ctx, withOutput(options, OutputTable))\n}","preventionTips":["Use official kops binaries; unmarshalable fields usually indicate patched builds.","Keep kops and cluster versions aligned.","Fall back to table output for human use; reserve JSON for scripts.","File upstream bug with the %v cause if reproducible."],"tags":["json","serialization","kops"],"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-12T07:17:12.445Z"}