Created
July 21, 2014 09:25
-
-
Save njern/8a0c5a2ad09624bbf0fe to your computer and use it in GitHub Desktop.
Reading and parsing JSON from a file in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"io/ioutil" | |
"log" | |
) | |
file, err := ioutil.ReadFile("file.json") | |
if err != nil { | |
log.Fatalf("Could not file: %v", err) | |
} | |
var v interface{} | |
if err := json.Unmarshal(file, &v); err != nil { | |
log.Fatalf("Error parsing JSON: %v", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment