diff --git a/json_server.js b/json_server.js
index 0c682d9..607972d 100644
--- a/json_server.js
+++ b/json_server.js
@@ -15,6 +15,9 @@ Drupal.toJson = function(v) {
       for(i in v) {
         output = output + i + ":" + Drupal.toJson(v[i]) + ",";
       }
+      if (output[output.length - 1] == ',') {
+        output = output.substring(0, output.length - 1);
+      }
       output = output + "}";
       return output;
     default:
