Generate utf-8 JSON when possible

Like #286.