Fix json output of collocatordb_query

Change-Id: Ib8c2960f276107f7fe5dbf1699ff5b20f1315166
diff --git a/examples/collocatordb_query.c b/examples/collocatordb_query.c
index 2336f85..f75f0c7 100644
--- a/examples/collocatordb_query.c
+++ b/examples/collocatordb_query.c
@@ -4,15 +4,18 @@
 #include <math.h>
 #include "../src/collocatordb.h"
 
-int main(int argc, char* argv[]) {
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <dbpath> <word1> [word2] ... [wordN]\n", argv[0]);
-        return 1;
-    }
+int main(int argc, char *argv[]) {
+  if (argc < 3) {
+    fprintf(stderr,
+            "Usage: %s <dbpath> <word1> [word2] ... [wordN]\n"
+            "Gets the collocators of the given words from a collocatordb and "
+            "prints them as json.\n"
+            "Example: %s ../tests/data/wpd19_10000 geht auch\n",
+            argv[0], argv[0]);
+    return 1;
+  }
 
-
-
-    char *dbpath = argv[1];
+  char *dbpath = argv[1];
     char *ext = strrchr(dbpath, '.');
     if (ext && strcmp(ext, ".rocksdb") == 0) {
         *ext = '\0';
@@ -28,6 +31,8 @@
     fprintf(stderr, "Successfully opened %s.\n", dbpath);
 
     int i;
+
+    printf("[\n");
     for (i = 2; i < argc; i++) {
         uint32_t word_id = get_word_id(cdb, argv[i]);
         if (word_id == 0) {
@@ -35,9 +40,9 @@
             continue;
         }
 
-        printf("printing collocators of \"%s\" as json:\n", argv[i]);
-        printf("%s\n", get_collocators_as_json(cdb, word_id));
+        fprintf(stderr, "printing collocators of \"%s\" as json:\n", argv[i]);
+        printf("%s%s\n", get_collocators_as_json(cdb, word_id), i < argc - 1 ? "," : "");
     }
-
+    printf("]\n");
     return 0;
 }
\ No newline at end of file