4 ms·
Yes, but the blog post makes it pretty clear that easy JSON decoding/encoding is a primary goal, and this is not friendly to that.
by mitchellh 12y ago
Yes, but the blog post makes it pretty clear that easy JSON decoding/encoding is a primary goal, and this is not friendly to that.
- deleted 12y ago[deleted]
- deleted 12y ago[deleted]
- deleted 12y ago[deleted]
- staunch 12y agofunc (ns NullString) MarshalJSON() ([]byte, error) { if !ns.Valid { return []byte("null"), nil } return json.Marshal(ns.String) } It would render `user_id: null` instead of `user_id: ""` which should work, I think.
- willnorris 12y agosure it's valid JSON, but it really depends on the API as to whether it handles null values properly when it's expecting some other type. I honestly haven't tried that with the GitHub API, but based on what I've seen it probably handles it fine. Others may not.
- deleted 12y ago[deleted]
- kyrra 12y agoAnd this is the problem about using null as a valid state for data. In many languages, using null as a valid data value just can cause all kinds of problem (extra checks, not supported, or problems accessing null data).