I am having trouble with unmarshaling the json data read from a .json
file
type redisConfig struct {
host string
password string
}
func loadRedisConfig() (redisConfig, error){
b, _ := ioutil.ReadFile("config.json")
var config redisConfig
fmt.Println(b)
fmt.Println(string(b))
e := json.Unmarshal(b, &config)
fmt.Println(e)
fmt.Println(config)
return config, nil;
}
The file config.json
contains this:
{
"host": "example.com",
"password": "password"
}
I have verified that it is valid JSON using http://jsonlint.com/. Reading other similar questions here on SO I saw that the issue was invalid json, I do not think that is the case here.
Here is the output from running the code snippet:
[123 13 10 32 32 34 104 111 115 116 34 58 32 34 101 120 97 109 112 108 101 46 99 111 109 34 44 13 10 32 32 34 112 97 115 115 119 111 114 100 34 58 32 34 112 97 115 115 119 111 114 100 34 13 10 125]
{
"host": "example.com",
"password": "password"
}
<nil>
{ }
The config
variable contains an empty struct, it should be populated with the marshaled json provided by the file and decoder