How Do I Parse a JSON file into a struct with Go

You’re not exporting your struct elements. They all begin with a lower case letter.

var settings struct {
    ServerMode bool `json:"serverMode"`
    SourceDir  string `json:"sourceDir"`
    TargetDir  string `json:"targetDir"`
}

Make the first letter of your stuct elements upper case to export them. The JSON encoder/decoder wont use struct elements which are not exported.

Leave a Comment