encoding/

directory
v0.0.0-...-4344c7c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2016 License: Apache-2.0

README

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 libary.
  • This package gets better and better with every release.

http://www.goinggo.net/2014/01/decode-json-documents-in-go.html

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.

Directories

Path Synopsis
Sample program to show how to unmarshal a JSON document into a user defined struct type.
Sample program to show how to unmarshal a JSON document into a user defined struct type.
Sample program to show how to unmarshal a JSON document into a user defined struct type from a file.
Sample program to show how to unmarshal a JSON document into a user defined struct type from a file.
Sample program to show how to marshal a user defined struct type into a string.
Sample program to show how to marshal a user defined struct type into a string.
Sample program to show how write a custom Unmarshal and Marshal functions.
Sample program to show how write a custom Unmarshal and Marshal functions.
exercises
exercise1
Create a file with an array of JSON documents that contain a user name and email address.
Create a file with an array of JSON documents that contain a user name and email address.
template1
Create a file with an array of JSON documents that contain a user name and email address.
Create a file with an array of JSON documents that contain a user name and email address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL