package main import ( "encoding/json" "fmt" ) type Response struct { Page int `json:"page"` Words []string `json:"words, omitempty"` } func main() { r := &Response{Page: 1, Words: []string{"Leena", "Sami", "Sara", "Zaki"}} j, _ := json.MarshalIndent(r, "", " ") fmt.Println(string(j)) }