{"record":{"id":"6dd42db34539026e","repo":"kubernetes/kops","slug":"error-marshaling-manifest-to-json-w","errorCode":null,"errorMessage":"error marshaling manifest to json: %w","messagePattern":"error marshaling manifest to json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/kubemanifest/manifest.go","lineNumber":139,"sourceCode":"\n\t\tyamls = append(yamls, y)\n\t}\n\n\treturn bytes.Join(yamls, yamlSeparator), nil\n}\n\nfunc (m *Object) ToYAML() ([]byte, error) {\n\tb, err := yaml.Marshal(m.data)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling manifest to yaml: %w\", err)\n\t}\n\treturn b, nil\n}\n\nfunc (m *Object) MarshalJSON() ([]byte, error) {\n\tb, err := json.Marshal(m.data)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling manifest to json: %w\", err)\n\t}\n\treturn b, nil\n}\n\nfunc (m *Object) accept(visitor Visitor) error {\n\terr := visit(visitor, m.data, []string{}, func(v interface{}) {\n\t\tklog.Fatal(\"cannot mutate top-level data\")\n\t})\n\treturn err\n}\n\n// IsEmptyObject checks if the object has no keys set (i.e. `== {}`)\nfunc (m *Object) IsEmptyObject() bool {\n\treturn len(m.data) == 0\n}\n\n// Kind returns the kind field of the object, or \"\" if it cannot be found or is invalid\nfunc (m *Object) Kind() string {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/kubemanifest/manifest.go#L121-L157","documentation":"Object.MarshalJSON marshals the object's underlying generic data map with encoding/json and wraps failures with this error. It exists so kubemanifest.Object can be embedded into other JSON structures; a failure means the data map contains values json.Marshal cannot encode.","triggerScenarios":"Using kubemanifest.Object as a field in a struct being json.Marshal'ed (e.g. addon manifests serialized into other output) while its data contains unencodable values such as channels, funcs, or cyclic references.","commonSituations":"Embedding parsed manifests in JSON output/debug dumps; programmatic mutation injecting Go values that aren't JSON encodable.","solutions":["Inspect the data map for non-JSON-encodable values (funcs, channels, cycles) and remove/convert them","Use the wrapped error to locate the offending value","Re-parse the manifest from source YAML to get a clean data map","If custom values are needed, give them MarshalJSON implementations"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := json.Marshal(obj.Data()); err != nil {\n\treturn fmt.Errorf(\"object not JSON-encodable: %w\", err)\n}\n","typeGuard":null,"tryCatchPattern":"out, err := json.Marshal(structWithEmbeddedObject)\nif err != nil && strings.Contains(err.Error(), \"marshaling manifest to json\") {\n\treturn fmt.Errorf(\"embedded manifest object is not JSON-encodable: %w\", err)\n}\n","preventionTips":["Ensure data map values are JSON encodable before embedding Object in structs","Give custom types MarshalJSON methods","Avoid cyclic references in mutated manifests","JSON round-trip test objects before serialization"],"tags":["json","serialization","go"],"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"}