{"record":{"id":"57c119514df89636","repo":"XTLS/Xray-core","slug":"failed-to-decode-config-57c119","errorCode":null,"errorMessage":"failed to decode config: ","messagePattern":"failed to decode config: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main/json/json.go","lineNumber":32,"sourceCode":")\n\nfunc init() {\n\tcommon.Must(core.RegisterConfigLoader(&core.ConfigFormat{\n\t\tName:      \"JSON\",\n\t\tExtension: []string{\"json\"},\n\t\tLoader: func(input interface{}) (*core.Config, error) {\n\t\t\tswitch v := input.(type) {\n\t\t\tcase cmdarg.Arg:\n\t\t\t\tcf := &conf.Config{}\n\t\t\t\tfor i, arg := range v {\n\t\t\t\t\terrors.LogInfo(context.Background(), \"Reading config: \", arg)\n\t\t\t\t\tr, err := confloader.LoadConfig(arg)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, errors.New(\"failed to read config: \", arg).Base(err)\n\t\t\t\t\t}\n\t\t\t\t\tc, err := serial.DecodeJSONConfig(r)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, errors.New(\"failed to decode config: \", arg).Base(err)\n\t\t\t\t\t}\n\t\t\t\t\tif i == 0 {\n\t\t\t\t\t\t// This ensure even if the muti-json parser do not support a setting,\n\t\t\t\t\t\t// It is still respected automatically for the first configure file\n\t\t\t\t\t\t*cf = *c\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tcf.Override(c, arg)\n\t\t\t\t}\n\t\t\t\treturn cf.Build()\n\t\t\tcase io.Reader:\n\t\t\t\tif serial.UseStrictJSON {\n\t\t\t\t\tcfg, err := serial.DecodeJSONConfigStrict(v)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t\treturn cfg.Build()\n\t\t\t\t}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/main/json/json.go#L14-L50","documentation":"The JSON loader successfully read the input but serial.DecodeJSONConfig could not parse it into a *conf.Config. This is a syntax-level or structure-level JSON failure: invalid JSON, wrong types for Xray fields, or (when strict mode is enabled via serial.UseStrictJSON in the io.Reader branch) unknown/duplicate fields. The parse error is chained as the Base cause with line/column information.","triggerScenarios":"Trailing commas, unquoted keys, comments in JSON, mismatched braces in a .json config; or values of the wrong type (string where number expected). With strict mode: fields not defined in the schema, such as legacy v2ray keys removed in Xray.","commonSituations":"Hand-editing JSON configs and breaking syntax, pasting YAML or TOML snippets into a .json file, port written as string \"443\" instead of number, or migrating configs between v2ray and Xray with incompatible keys.","solutions":["Validate the file with a JSON linter: jq empty config.json shows exact line/column of the error","Remove comments and trailing commas; quote all keys; use numbers for ports","Cross-check field names/types against Xray's JSON config schema (infra/conf)","Rename the file to .yaml/.toml only if the content really is that format, so the right loader parses it"],"exampleFix":"// before\n{\n  \"inbounds\": [{ \"port\": \"443\", \"protocol\": \"dokodemo-door\" }]  // port as string, comment\n}\n\n// after\n{\n  \"inbounds\": [{ \"port\": 443, \"protocol\": \"dokodemo-door\" }]\n}","handlingStrategy":"validation","validationCode":"// pre-validate before handing to Xray\nif data, err := os.ReadFile(cfgPath); err == nil {\n    if !json.Valid(data) { log.Fatalf(\"invalid JSON in %s\", cfgPath) }\n}","typeGuard":null,"tryCatchPattern":"if err := load(); err != nil {\n    var syn *json.SyntaxError\n    if errors.As(err, &syn) { pointAt(cfgPath, int(syn.Offset)) }\n}","preventionTips":["Run jq empty / jsonlint on every config change","Reject configs with comments or trailing commas in CI","Generate configs programmatically (marshal from structs) instead of hand-editing"],"tags":["go","xray","json","config","parsing"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}