Skip to content

Instantly share code, notes, and snippets.

@njern
Created July 21, 2014 09:25
Show Gist options
  • Save njern/8a0c5a2ad09624bbf0fe to your computer and use it in GitHub Desktop.
Save njern/8a0c5a2ad09624bbf0fe to your computer and use it in GitHub Desktop.
Reading and parsing JSON from a file in Go
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