XTLS/Xray-core · error
failed to convert yaml to json
Error message
failed to convert yaml to json
What it means
Raised in DecodeYAMLConfig when ghodss/yaml cannot convert the YAML document to JSON — YAML syntax error or YAML features without JSON equivalents (anchors producing non-serializable nodes, wrong types). The conversion error is wrapped as Base.
Solutions
- Fix the YAML syntax error in the Base message
- Ensure all values map to JSON-compatible types
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at infra/conf/serial/loader.go:151 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/f2e9ba11f79be9a4.
Report an issue: GitHub.
Appendix: source
Thrown at infra/conf/serial/loader.go:151
pbConfig, err := tomlConfig.Build()
if err != nil {
return nil, errors.New("failed to parse toml config").Base(err)
}
return pbConfig, nil
}
// DecodeYAMLConfig reads from reader and decode the config into *conf.Config
// using github.com/ghodss/yaml to convert yaml to json.
func DecodeYAMLConfig(reader io.Reader) (*conf.Config, error) {
yamlFile, err := io.ReadAll(reader)
if err != nil {
return nil, errors.New("failed to read config file").Base(err)
}
jsonFile, err := yaml.YAMLToJSON(yamlFile)
if err != nil {
return nil, errors.New("failed to convert yaml to json").Base(err)
}
return DecodeJSONConfig(bytes.NewReader(jsonFile))
}
func LoadYAMLConfig(reader io.Reader) (*core.Config, error) {
yamlConfig, err := DecodeYAMLConfig(reader)
if err != nil {
return nil, err
}
pbConfig, err := yamlConfig.Build()
if err != nil {
return nil, errors.New("failed to parse yaml config").Base(err)
}
return pbConfig, nil
}View on GitHub (pinned to 7d214f8b09)