We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.19.0
1.23.3
Files
JSON
No response
package main import ( "fmt" "io" "os" ) import "github.com/spf13/viper" func printConfig() { f, err := os.OpenFile("./config.json", os.O_RDONLY, os.ModePerm) if err != nil { panic(err) } data, err := io.ReadAll(f) if err != nil { panic(err) } fmt.Println(string(data)) } func main() { printConfig() viper.SetConfigName("config") viper.SetConfigType("json") viper.AddConfigPath(".") err := viper.ReadInConfig() if err != nil { panic(fmt.Errorf("fatal error config file: %w", err)) } viper.Set("person.0.detail.age", 29) err = viper.WriteConfig() if err != nil { panic(fmt.Errorf("fatal error config file: %w", err)) } printConfig() }
source config json file
{ "person": [ { "detail": { "age": 18 } } ] }
after call function
viper.Set("person.0.detail.age", 29)
this config file should be
{ "person": [ { "detail": { "age": 29 } } ] }
this config file was changed like this
{ "person": { "0": { "detail": { "age": 29 } } } }
1.create config.json in current project directory and input content
2.go run main.go
3.watch the config.json data
In some programming languages like JavaScript, maybe person[0] is same to person["0"], but the changed of 'data struct' maybe cause confused issues.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Preflight Checklist
Viper Version
1.19.0
Go Version
1.23.3
Config Source
Files
Format
JSON
Repl.it link
No response
Code reproducing the issue
Expected Behavior
source config json file
after call function
this config file should be
Actual Behavior
source config json file
after call function
this config file was changed like this
Steps To Reproduce
1.create config.json in current project directory and input content
2.go run main.go
3.watch the config.json data
Additional Information
In some programming languages like JavaScript, maybe person[0] is same to person["0"], but the changed of 'data struct' maybe cause confused issues.
The text was updated successfully, but these errors were encountered: