ConvertersLesson 32Free preview
JSON to Go
This lesson is part of Web Developer Tools · All levels
Summary
The JSON to Go converter produces a struct declaration with a field representing each JSON key. The field must be prefixed with capital letters in order to be accessible from another package, whereas the json tag specifies the key name when serialized. The data type is mapped to string, int, float64, bool, slice, or cluster struct. The result can be used directly with json encoding to read and write JSON.
Key points
- Create a struct Go with a field according to the JSON key
- The field name must be prefixed with capital letters in order to export
- Tag like `json:"nama"` map a field to a JSON key
- The array becomes a slice and the object clusters into a struct
- Package encoding/json handling the marshal and unmarshal
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.