Improve error reporting when serializing non-Unicode strings to JSON