---
# System prepended metadata

title: Untitled

---

type FooBar struct {
   n int
}

type Task struct {
   T *FooBar `json:"t,omitempty"`
}



json.Marshal(Task{FooBar{n: 4}}) > {t: ""}
json.Marshal(Task{FooBar{n: 3}}) > {t: "foo"}
json.Marshal(Task{FooBar{n: 5}}) > {t: "bar"}
json.Marshal(Task{FooBar{n: 15}}) > {t: "foobar"}

n divisible? 3 = "foo"
n divisible? 5 = "bar"
n divisible? 3 and divisible? 5 = "foobar"
otherwise ""

MarshalJSON()


func (t *Foobar) MarshalJSON() ([]byte, error) {
    three := t.n % 3 == 0;
    five := t.n % 5 == 0;
    
    if three && five {
        return []byte("foobar"), nil
    }
    if three {
        return []byte("foo"), nil
    }
    if five {
        return []byte("bar"), nil
    }
    
    return []byte(""),nil
}