diff --git a/src/json.hpp b/src/json.hpp
index 57a8f4c7..65ced730 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -6078,9 +6078,11 @@ class basic_json
                     {
                         // convert a number 0..15 to its hex representation
                         // (0..f)
-                        auto hexify = [](const char v) -> char
+                        const auto hexify = [](const int v) -> char
                         {
-                            return (v < 10) ? ('0' + v) : ('a' + v - 10);
+                            return (v < 10)
+                            ? ('0' + static_cast<char>(v))
+                            : ('a' + static_cast<char>(v - 10));
                         };
 
                         // print character c as \uxxxx
diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c
index cdd96ee9..0aa8321e 100644
--- a/src/json.hpp.re2c
+++ b/src/json.hpp.re2c
@@ -6078,9 +6078,11 @@ class basic_json
                     {
                         // convert a number 0..15 to its hex representation
                         // (0..f)
-                        auto hexify = [](const char v) -> char
+                        const auto hexify = [](const int v) -> char
                         {
-                            return (v < 10) ? ('0' + v) : ('a' + v - 10);
+                            return (v < 10)
+                            ? ('0' + static_cast<char>(v))
+                            : ('a' + static_cast<char>(v - 10));
                         };
 
                         // print character c as \uxxxx