Repository navigation
Can Viper convert between formats? #1799
Unanswered
flibby-jibbit
asked this question in
Q&A
Replies: 1 comment
|
Yes. Read the TOML file and write to a filename with a YAML extension: func convertConfig() error {
v := viper.New()
v.SetConfigFile("config.toml")
if err := v.ReadInConfig(); err != nil {
return err
}
return v.SafeWriteConfigAs("config.yaml")
}Import I tested this with Viper v1.21.0 and read the generated YAML back into a fresh instance: nested string and integer values were preserved. The output encoder is chosen from the destination extension in This converts configuration values; comments, original formatting, and key casing are not preserved. Use a fresh instance for the conversion so unrelated defaults or environment/flag overrides are not included in the output. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Suppose I have a configuration file in TOML, can I read that in and then write it out in YAML?
All reactions