Encoding is the process or marshaling or unmarshaling data into different forms. Taking JSON string documents and convert them to values of our user defined types is a very common practice in many go programs today. Go's support for encoding is amazing and improves and gets faster with every release.
- Support for Decoding and Encoding JSON and XML are provided by the standard library.
- This package gets better and better with every release.
Decode JSON Documents In Go - William Kennedy
Unmarshal JSON documents (Go Playground)
Unmarshal JSON files (Go Playground)
Marshal a user defined type (Go Playground)
Custom Marshaler and Unmarshler (Go Playground)
Part A 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.
Part B Marshal the slice into pretty print strings and display each element.
Template (Go Playground) | Answer (Go Playground)
All material is licensed under the Apache License Version 2.0, January 2004.