// You need a struct to unmarshal file:
// After running this function with Some_struct,
// your object will be filled with json file data
func parseJsonFile(file string, obj *Some_struct) {
jsonFile, err := os.Open(file)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err, "| Can find a file")
} else {
fmt.Println("File found!")
}
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
// read our opened xmlFile as a byte array.
byteValue, _ := ioutil.ReadAll(jsonFile)
// we unmarshal our byteArray which contains our
// jsonFile's content into 'users' which we defined above
json.Unmarshal(byteValue, &obj)
}
{
"origin": "golangdocs.com",
"user": "Vijay",
"active": true
}