diff --git a/components/micropython/vendor/extmod/modujson.c b/components/micropython/vendor/extmod/modujson.c
index c1ef20813289b18d967d96af299f5d1891c10049..df5391ad26094f59c8df78122ac59780669a5536 100644
--- a/components/micropython/vendor/extmod/modujson.c
+++ b/components/micropython/vendor/extmod/modujson.c
@@ -59,7 +59,8 @@ STATIC mp_obj_t mod_ujson_dump_helper(size_t n_args, const mp_obj_t *pos_args, m
     print_ext.indent_depth = 0;
     if (indent != mp_const_none) {
         if (mp_obj_is_int(indent)) {
-            mp_uint_t len_whitespace = mp_obj_get_int(indent);
+            mp_int_t len_whitespace = mp_obj_get_int(indent);
+            len_whitespace = len_whitespace > 0 ? len_whitespace : 0;
             char * whitespace = m_malloc(len_whitespace + 1);
             memset(whitespace, ' ', len_whitespace);
             whitespace[len_whitespace] = '\0';