Working with JSON in Go
Turn Go structs into JSON and back, control field names with struct tags, process JSON streams, reject unknown fields, and see what JSON v2 in Go 1.27 changes.
Welcome to the Go Tutorial. If you’re new here, you better start at the beginning.
Turn Go structs into JSON and back, control field names with struct tags, process JSON streams, reject unknown fields, and see what JSON v2 in Go 1.27 changes.
Define small interfaces that types satisfy implicitly, use fmt.Stringer, error, io.Reader and io.Writer, and unpack values with type switches.
Make decisions in Go with if, else and switch, including the short statement before a condition and why cases don’t fall through.
Write handlers, route requests with method and wildcard patterns, send and receive JSON, set timeouts, shut down gracefully and test it all with httptest.
Write one function or type that works with many types: type parameters, constraints, a generic Stack, Go 1.27 generic methods, and when not to use generics.
Write your own Go functions: parameters, multiple return values, variadic arguments, function values and closures.
Read and write whole files, go through a file line by line, append to logs, build portable paths, list directories and embed files in your binary.
Create, return, wrap and inspect errors in Go, from if err != nil to errors.Is, errors.As and errors.Join, and when to panic instead.
Cancel goroutines and put time limits on work with context.Context, and follow the conventions every Go API uses.
Declare constants with const, understand typed and untyped constants, and use iota to build enumerations.