Index: views-view-json.tpl.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_datasource/views-view-json.tpl.php,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 views-view-json.tpl.php
--- views-view-json.tpl.php	9 Jul 2008 06:47:58 -0000	1.1.2.3
+++ views-view-json.tpl.php	7 Oct 2008 15:52:40 -0000
@@ -29,28 +29,49 @@ foreach($rows as $row) {
 if ($options['format'] == 'Simple') json_simple_render($items, $view);
 if ($options['format'] == 'Exhibit') json_exhibit_render($items, $view);
 
+define('EXHIBIT_DATE_FORMAT', '%Y-%m-%d %H:%M:%S');	
+
 function json_simple_render($items, $view) {
-  define('EXHIBIT_DATE_FORMAT', '%Y-%m-%d %H:%M:%S');	
-	$json = '"nodes":'.str_repeat(" ", 4)."[\n";
-	foreach($items as $item) {
-		$json.= str_repeat(" ", 6)."{\n";
+  // According to the Drupal JS coding standards, we use
+  // 1 space to separate an object name from a val, and 
+  // two spaces for each indent level.
+	$json = "[\n";
+	$pair_format = '    "%s": "%s"';
+	$num_items = count($items); 
+	for($i = 0; $i < $num_items; ++$i) {
+	  $item = $items[$i];
+	  
+	  // Add a comma between vals.
+	  $json .= "  {\n";
+		$pairs = array();
+		
 		foreach($item as $itemfield) {
 			$itemfieldarray = explode(":", $itemfield);
-
+			
 			/*replace escaped colons with actual colon*/
 			$itemfieldarray[0] = str_replace('#colon#', ':', $itemfieldarray[0]);
 			$itemfieldarray[1] = str_replace('#colon#', ':', $itemfieldarray[1]);
 
 			$label = trim(views_json_strip_illegal_chars(views_json_encode_special_chars($itemfieldarray[0])));
-      $value = views_json_encode_special_chars(trim(views_json_is_date($itemfieldarray[1])));
-      if (strtotime($value))
-        $value = gmstrftime(EXHIBIT_DATE_FORMAT, strtotime($value));
+			
+			$value = trim($itemfieldarray[1]); // Want to trim before checking for date.
+			if (views_json_is_serialized_date($value)) {
+			  $date = unserialize($value);
+			  $time = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
+			  $value = gmstrftime(EXHIBIT_DATE_FORMAT, $time);
+			}
+			$value = views_json_encode_special_chars($value);
+			
       $label = str_replace('_value', '', str_replace("profile_values_profile_", '', $label)); //strip out Profile: from profile fields
-      $json.=str_repeat(" ", 8).'"'.$label.'"'. " ".": ".'"'.$value.'"'.",\n";
+      $pairs[] = sprintf($pair_format, $label, $value);
+		}
+		$json .= implode(",\n", $pairs) . "\n  }";
+		if ($i < $num_items - 1) {
+		  $json .= ',';
 		}
-		$json.=str_repeat(" ", 6)."},\n\n";	
+		$json .= "\n\n";
 	}
-	$json.=str_repeat(" ", 4)."]";
+	$json .= "]";
   /*
    * The following will cause an error in a live view preview - comment out if
    * debugging in there.
@@ -68,7 +89,7 @@ function json_simple_render($items, $vie
 }
 
 function json_exhibit_render($items, $view) {
-  define('EXHIBIT_DATE_FORMAT', '%Y-%m-%d %H:%M:%S');
+//  define('EXHIBIT_DATE_FORMAT', '%Y-%m-%d %H:%M:%S');
   $json = "{\n".str_repeat(" ", 4).'"items"'." : ". "[\n";
   foreach ($items as $item) { 
   	$json.=str_repeat(" ", 8)."{\n";
Index: views_json.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_datasource/views_json.module,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 views_json.module
--- views_json.module	8 Jul 2008 19:43:38 -0000	1.1.2.1
+++ views_json.module	7 Oct 2008 15:52:40 -0000
@@ -1,10 +1,10 @@
 <?php
 //$Id: views_json.module,v 1.1.2.1 2008/07/08 19:43:38 allisterbeharry Exp $
 /**
- @file views_json.module
- Module definition for views_json 
- @see views_json.views.inc
-*/
+ * @file views_json.module
+ * Module definition for views_json 
+ * @see views_json.views.inc
+ */
 
 /**
  * Strips illegal JSON characters in identifier string
@@ -14,40 +14,63 @@
  */
 
 function views_json_strip_illegal_chars($input) {
- $output = str_replace(array('{','}','[', ']', ':', ',', '"', "'", chr(47), chr(92)), '', $input);
- $output = preg_replace(
-                        '/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP
-                        '\x{01}-\x{1F}'. //Non-printable ASCII characters
-                        '\x{0}]/u', // NULL byte
-        '', $output);
+  $output = str_replace(array('{','}','[', ']', ':', ',', '"', "'", chr(47), chr(92)), '', $input);
+  $output = preg_replace(
+      '/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP
+      '\x{01}-\x{1F}'. //Non-printable ASCII characters
+      '\x{0}]/u', // NULL byte
+    '', $output);
 
- return $output;  
+  return $output;  
 }
 
 /**
- * Encodes special JSON characters in string
+ * Encodes special JSON characters in string.
  *
- * @param string $input
+ * See http://www.json.org for details.
+ *
+ * @param $input
+ *  Text to be escaped.
  * @return string
+ *  Escaped text, following the JSON standard.
  */
 function views_json_encode_special_chars($input) {
-  $output = str_replace(chr(92), '\\', $input);
-  $output = str_replace(chr(47), '\/', $output);
-  $output = str_replace('"', '\"', $output);
-  $output = str_replace(chr(8), '\b', $output);
-  $output = str_replace(chr(12), '\f', $output);
-  $output = str_replace(chr(13).chr(10), '\n', $output);
-  $output = str_replace(chr(10), '\n', $output);
-  $output = str_replace(chr(13), '\r', $output);
-  $output = str_replace(chr(9), '\t', $output);
-  return $output;
+  // Chars that will be escaped.
+  $escape = array(
+    chr(92),
+    chr(47),
+    chr(8),
+    chr(12),
+    chr(13),
+    chr(10),
+    chr(13),
+    chr(9),
+    '"',
+  );
+  // Use one fast function call to do all translations.
+  return addcslashes($input, implode('',$escape));  
+}
+
+/**
+ * Check to see if a given string is a serialized date.
+ * 
+ * @param $str
+ *  This candidate string is checked to see if it is a date in
+ *  PHP serialized form.
+ * @return Boolean
+ *  TRUE if this is a serialized date, false otherwise.
+ */
+function views_json_is_serialized_date($str) {
+  return (strpos($input, 'a:3:{s:5:"month"') === 0);
 }
 
 /**
  * If input is a serialized date array, return a date string 
  *
- * @param unknown_type $input
- * @return unknown
+ * @param $input
+ *  A string
+ * @return 
+ * A formatted data string, or the original string.
  */
 function views_json_is_date ($input) {
   if (strpos($input, 'a:3:{s:5:"month"') !== 0) return $input; 
