diff --git a/plot_serializer/serializer.py b/plot_serializer/serializer.py
index 6955dee5979d145769a5d64f0f6f5a3a3fef8299..023e96bcb28a47cb56d9d2d6265bb9264bc4b921 100644
--- a/plot_serializer/serializer.py
+++ b/plot_serializer/serializer.py
@@ -418,9 +418,7 @@ class Serializer:
         if self._written_to_file:
             raise NotImplementedError("You can only write the figure into the JSON once! Multiple tries were attempted")
         if isinstance(file, str):
-            directory = os.path.dirname(file)
-            if directory:
-                os.makedirs(directory, exist_ok=True)
+            os.makedirs(os.path.dirname(file), exist_ok=True)
             with open(file, "w") as file:
                 self.write_json_file(file)
         else: