{"record":{"id":"8750d225dc7e1ffe","repo":"XTLS/Xray-core","slug":"marshal-to-json-failed","errorCode":null,"errorMessage":"marshal to json failed.","messagePattern":"marshal to json failed\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infra/conf/serial/builder.go","lineNumber":33,"sourceCode":"// UseStrictJSON, when true, makes JSON config decoders skip the custom\n// comment-stripping reader and parse input as strict RFC 8259 JSON.\n//\n// Enabled by setting the env variable xray.json.strict=true (or its normalized\n// form XRAY_JSON_STRICT=true). Default false preserves backward-compatible\n// behavior for human-edited configs that may contain comments or other\n// JSON5/JSONC syntax.\nvar UseStrictJSON = platform.NewEnvFlag(platform.UseStrictJSON).GetValue(func() string { return \"\" }) == \"true\"\n\nfunc MergeConfigFromFiles(files []*core.ConfigSource) (string, error) {\n\tc, err := mergeConfigs(files)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif j, ok := creflect.MarshalToJson(c, true); ok {\n\t\treturn j, nil\n\t}\n\treturn \"\", errors.New(\"marshal to json failed.\").AtError()\n}\n\nfunc mergeConfigs(files []*core.ConfigSource) (*conf.Config, error) {\n\tcf := &conf.Config{}\n\tfor i, file := range files {\n\t\terrors.LogInfo(context.Background(), \"Reading config: \", file)\n\t\tr, err := confloader.LoadConfig(file.Name)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"failed to read config: \", file).Base(err)\n\t\t}\n\t\tdecoder := ReaderDecoderByFormat[file.Format]\n\t\tif file.Format == \"json\" && UseStrictJSON {\n\t\t\tdecoder = DecodeJSONConfigStrict\n\t\t}\n\t\tc, err := decoder(r)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"failed to decode config: \", file).Base(err)\n\t\t}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/serial/builder.go#L15-L51","documentation":"Error \"marshal to json failed.\" thrown in XTLS/Xray-core.","triggerScenarios":"Thrown at infra/conf/serial/builder.go:33 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}