golang json omitempty struct

Solutions on MaxInterview for golang json omitempty struct by the best coders in the world

showing results for - "golang json omitempty struct"
Lotta
28 Jan 2020
1import (
2    "fmt"
3    "github.com/clarketm/json" // drop-in replacement for `encoding/json`
4)
5
6type Result struct {
7    Data   MyStruct `json:"data,omitempty"`
8    Status string   `json:"status,omitempty"`
9    Reason string   `json:"reason,omitempty"`
10}
11
12j, _ := json.Marshal(&Result{
13    Status: "204",
14    Reason: "No Content",
15})
16
17fmt.Println(string(j))
18
similar questions
queries leading to this page
golang json omitempty struct