diff --git a/src/weight_calculation/main.cpp b/src/weight_calculation/main.cpp
index 6ffb2e513e1aa2e8a1ccdfff77dfc7b96d02c8b2..9c51b5e52239fac6b0a6f62ed5384e2ce5d35229 100644
--- a/src/weight_calculation/main.cpp
+++ b/src/weight_calculation/main.cpp
@@ -13,19 +13,27 @@ bool calculateWeight(SQLite::Database & db, std::ofstream & ostream, const json
     uint32_t occurrences;
     double weight;
     maxOccurrences[term].get_to(occurrences);
+    bool firstOccurrence = true;
 
     try
     {
-        SQLite::Statement query(db, "SELECT * FROM TermDocumentOccurrence JOIN Term ON TermDocumentOccurrence.Term_id = Term.id WHERE Term.value = :term");
+        SQLite::Statement query(db, "SELECT * FROM TermDocumentOccurrence "
+                                        "JOIN Term ON TermDocumentOccurrence.Term_id = Term.id "
+                                        "WHERE Term.value = :term "
+                                        "ORDER BY TermDocumentOccurrence.Document_id ASC");
         query.bind(":term", term);
 
-        ostream << term << ":";
+        ostream << "\"" << term << "\":{";
         while(query.executeStep())
         {
+            if (!firstOccurrence)
+                ostream << ",";
+            firstOccurrence = false;
+
             weight = query.getColumn("count").getInt() / (occurrences*1.0);
-            ostream << " " << query.getColumn("Document_id") << " " << std::setprecision(20) << weight;
+            ostream << "\"" << query.getColumn("Document_id") << "\":" << std::setprecision(20) << weight;
         }
-        ostream << std::endl;
+        ostream << "}";
     }
 
     catch(const std::exception& e)
@@ -43,10 +51,20 @@ bool process(std::ofstream & ostream, const json & maxOccurrences)
     {
         SQLite::Database db("./../data/persistance/db", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
         SQLite::Statement query(db, "SELECT value FROM Term");
+        bool firstTerm = true;
 
+        ostream << "{";
         while (query.executeStep())
+        {
+            if(!firstTerm)
+                ostream << ",";
+            firstTerm = false;
+
             if(!calculateWeight(db, ostream, maxOccurrences, query.getColumn("value")))
                 return false;
+        }
+
+        ostream << "}";
     }
 
     catch(const std::exception& e)