Skip to content

Instantly share code, notes, and snippets.

@znbailey
Created June 2, 2013 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save znbailey/5695121 to your computer and use it in GitHub Desktop.
Save znbailey/5695121 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
type Policy struct {
Name string
Value string
}
type Policies struct {
Policies []Policy
}
func main() {
filename := "policies.json"
jsonRaw, readErr := ioutil.ReadFile(filename)
if readErr != nil {
fmt.Println(readErr)
}
var policies Policies
decodeErr := json.Unmarshal(jsonRaw, &policies)
if decodeErr != nil {
panic(decodeErr)
}
fmt.Println(policies);
}
{
"Policies": [
{
"Name" : "Policy 1",
"Value": "foo"
},
{
"Name" : "Policy 2",
"Value": "bar"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment