diff --git a/includes/output.inc b/includes/output.inc
index f036e34..438e0dd 100644
--- a/includes/output.inc
+++ b/includes/output.inc
@@ -74,14 +74,20 @@ function drush_print_r($array, $handle = NULL) {
  * @param mixed $input
  *   A variable.
  * @param string $label
- *   Optional prefix. Not used by JSON format.
+ *   Optional prefix.
+ * @param string $format
+ *   Optional formatter setting to use. Available options are "export",
+ *   "print_r", "json", etc. Defaults to "print_r".
  * @return string
  *   The variable formatted according to specified format. Ready for drush_print().
  */
 function drush_format($input, $label = NULL, $format = NULL) {
+  // Retrieve which formatter to use, defaulting to print_r.
   if (is_null(($format))) {
     $format = drush_get_option('format', 'print_r');
   }
+
+  // Boolean values are switched to strings, except with the export formatter.
   if ($format != 'export') {
     if ($input === TRUE) {
       $input = 'TRUE';
@@ -91,34 +97,43 @@ function drush_format($input, $label = NULL, $format = NULL) {
     }
   }
 
-  switch ($format) {
-    case 'export':
-      if ($label) {
-        $output = "\$variables['$label'] = " . var_export($input, TRUE) . ';';
-      }
-      else {
-        $output = var_export($input, TRUE);
-      }
-      break;
-    case 'json':
-      $output = drush_json_encode($input);
-      break;
-    case 'print_r':
-    default:
-      if (is_string($input)) {
-        $input = '"' . $input . '"';
-      }
-      elseif (is_array($input) || is_object($input)) {
-        $input = print_r($input, TRUE);
-      }
+  // Make sure the format is available.
+  if (!function_exists('drush_format_' . $format)) {
+    // Display the formatter error only once.
+    static $error = FALSE;
+    if (!$error) {
+      drush_set_error('DRUSH_FORMAT_NOT_FOUND', dt('Format !format not found. Using "print_r" instead.', array('!format' => $format)));
+      $error = TRUE;
+    }
+    $format = 'print_r';
+  }
 
-      if ($label) {
-        $input = $label . ': ' . $input;
-      }
-      $output = $input;
-      break;
+  // Contruct the output as defined by the formatter.
+  $function = 'drush_format_' . $format;
+  return $function($input, $label);
+}
+
+/**
+ * Formats variables using var_export.
+ */
+function drush_format_export($input, $label = NULL) {
+  if ($label) {
+    return "\$variables['$label'] = " . var_export($input, TRUE) . ';';
+  }
+  else {
+    return var_export($input, TRUE);
+  }
+}
+
+/**
+ * Formats variables with JSON.
+ */
+function drush_format_json($input, $label = NULL) {
+  // JSON can display the label as the key in an associative array.
+  if ($label) {
+    $input = array($label => $input);
   }
-  return $output;
+  return drush_json_encode($input);
 }
 
 /**
