NaN NaN - 1 month ago 16
JSON Question

Skip field in Beego when sending JSON

When sending JSON with ServeJSON in Beego, is there a way to skip fields? I know one can skip field for ORM: http://beego.me/docs/mvc/model/models.md#ignore-field but that is just for skipping fields in the database model, it is not related to sending JSON.

Answer

You can use the struct tag "-".

It should looks like :

type MyStruct struct {
    Id      int     `json:"id"`
    Hidden  string  `json:"-"`
}

It also works for the orm definition.

Comments