11. Encoding and Decoding (JSON)
Activity 11.01: Mimicking a Customer Order Using JSON
Solution:
All directories and files created need to be created within your $GOPATH
:
- Create a directory called
Activity11.01
within a directory calledChapter11
. - Create a file called
main.go
insideChapter11/Activity11.01
. - Using Visual Studio Code, open the newly created
main.go
file. - Add the following package name and import statements:
package main import ( Â Â "encoding/json" Â Â "fmt" Â Â "os" )
- Add the following
customer
struct
with the JSON tags set accordingly:type customer struct { Â Â UserName string `json:"username"` Â Â Password string `json:"-"` Â Â Token string `json:"-"` Â Â ShipTo address `json:"shipto"` Â Â PurchaseOrder order `json:"order"` }
- Add the following
order
struct
with...