odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.59k stars 575 forks source link

Add support of `ignore` tag for `json.marshal` #3914

Closed VladPavliuk closed 2 months ago

VladPavliuk commented 2 months ago

Propose an ability to specify optional ignore tag for struct fields to exclude them from json.marshal json object output.

Example:

My_Struct :: struct {
    a: string `json:"-"`,
}

my_struct := My_Struct{
    a = "test",
}

marshaled_data, _ := json.marshal(my_struct)

will produce:

{}
laytan commented 2 months ago

IMO it would be better to do json:"-" to match cbor:"-" and fmt:"-" which do the same thing in their respective packages.

gingerBill commented 2 months ago

Please use - not _.

VladPavliuk commented 2 months ago

@laytan @gingerBill thanks for pointing that out! I didn't know about that already existing ignore functionality in cbor and fmt. The changes where pushed to the branch.