Will the fields be omitted!?

Report a typo

Kendrick has created a Go program that has the Order struct with struct tags and optional directives on its fields:

...

type Item struct {
    Name  string
    Price float64
}

type Order struct {
    ID        int       `json:"id,string"`
    CreatedAt time.Time `json:"-"`
    Status    string    `json:"status,omitempty"`
    Items     []Item    `json:"items"`
    Total     float64   `json:"total"`
}

func main() {
    foodOrder := Order{
        ID:        1,
        CreatedAt: time.Now(),
        Items: []Item{
            {"pizza", 10.75},
        },
        Total: 10.75,
    }

    foodOrderJSON, err := json.Marshal(foodOrder)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(string(foodOrderJSON))
}

Select below the correct serialized output that the above program will produce. Take special notice of the directives that Kendrick has used for certain fields!

Select one option from the list
___

Create a free account to access the full topic