Andrew's Digital Garden

Struct tags in Go

Structs can be marshalled (encoded) into [[json]] easily using json.MarshalIndent from the encoding/json package. To create a desired JSON format without changing the underlying struct, field tags can be used.

To use JSON field tags:

type weatherData struct { LocationName string `json:"location"` Weather string `json:"weather"` }

[[go]] [[structs]]

Struct tags in Go