I don't think you're doing anything wrong implementing json.Marshaler.
I suspect the problem is that the JSON spec doesn't define an NaN
value (or infinity), but the Go package is using strconv internally,
which handles NaN. Trying to marshal any value containing NaN,
infinity, or -infinity should probably return an error.
- Evan