forked from ardanlabs/gotraining
/
template1.go
28 lines (19 loc) · 1019 Bytes
/
template1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// Create a file with an array of JSON documents that contain a user name and email address. Declare a struct
// type that maps to the JSON document. Using the json package, read the file and create a slice of this struct
// type. Display the slice.
//
// Marshal the slice into pretty print strings and display each element.
package main
// Add imports.
// Declare a struct type named user with two fields. Name of type string and
// Email of type string. Add tags for each field for the unmarshal call.
func main() {
// Use the os package to Open the JSON file. Check for errors.
// Schedule the file to be closed once the function returns.
// Declare a nil slice of user struct types.
// Decode the JSON from the file into the slice. Check for errors.
// Iterate over the slice and display each user value.
// Marshal each user value and display the JSON. Check for errors.
}