#More custom json

6 messages · Page 1 of 1 (latest)

lusty raven
#

If I have a struct that has

type User struct {
    gorm.Model
    ID int `gorm:"primary_key"`
//////// Stuff here 
    Vouch     []Vouches `                             json:"vouches"`
}

Sometimes I want the vouch field to be populated, sometimes I don't
When it's not populated, it still sends 0 values when I marshal it via json
How can I send nothing for the Vouch field, if I specify
using json:"-" just 0's it all the time

mighty swift
#

have you tried adding omitempty ?

lusty raven
#

I have just not on all of the fields, I'll try that now 🙂

lusty raven
#

@mighty swift Yeah that + removing some un-used fields changed size of request from 1.2M to 8KB

#

lol

mighty swift