Skip to content

Latest commit

 

History

History
32 lines (20 loc) · 1.74 KB

README.md

File metadata and controls

32 lines (20 loc) · 1.74 KB

Encoding - Standard Library

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.

Notes

  • Support for Decoding and Encoding JSON and XML are provided by the standard library.
  • This package gets better and better with every release.

Links

Decode JSON Documents In Go - William Kennedy

Code Review

Unmarshal JSON documents (Go Playground)
Unmarshal JSON files (Go Playground)
Marshal a user defined type (Go Playground)
Custom Marshaler and Unmarshler (Go Playground)

Exercises

Exercise 1

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.