It appears that the Marshal function from encoding/json treats false booleans as if they were nil values, and thus it omits them from the resulted json. I believe this behavior is a bug. I couldn't find reference in the json spec, but it has caused some issues with my client code, that makes a distinction between a non-existent boolean and a false boolean.
@cespare Considering golang's design where primitive types are always initialized to empty values, your comment makes perfect sense. So I realize this is not a bug, but it's also somewhat confusing and perhaps even unexpected. When writing go code, this isn't a big deal. But in the case of JSON data being passed from client to server (one of the largest use cases of JSON) , this makes go somewhat inconsistent with the rest of the world (clients and servers), and can confuse a lot of people. Not sure what a good solution would be.
@spenczar that's a great idea, thanks. That's exactly what I was after.
A boolean only has two values. You can either send false or not, depending on what tag you put on the variable. If you need a three-valued boolean, that's not a boolean. As @spenczar suggested, *bool is a good choice in this case.