9 // LoadJSON reads the given file and unmarshals its content.
10 func LoadJSON(file string, val interface{}) error {
11 content, err := ioutil.ReadFile(file)
15 if err := json.Unmarshal(content, val); err != nil {
16 if syntaxerr, ok := err.(*json.SyntaxError); ok {
17 line := findLine(content, syntaxerr.Offset)
18 return fmt.Errorf("JSON syntax error at %v:%v: %v", file, line, err)
20 return fmt.Errorf("JSON unmarshal error in %v: %v", file, err)
25 // findLine returns the line number for the given offset into data.
26 func findLine(data []byte, offset int64) (line int) {
28 for i, r := range string(data) {
29 if int64(i) >= offset {