Created
June 2, 2013 21:59
-
-
Save znbailey/5695121 to your computer and use it in GitHub Desktop.
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" | |
"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); | |
} |
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
{ | |
"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