fixes json errors

This commit is contained in:
SuperNovaa41 2024-01-29 12:17:44 -05:00
parent 1fd6c14b62
commit d97b6c80b8

View File

@ -19,6 +19,9 @@ std::string book_vec_to_json(std::vector<std::string> headers, std::vector<std::
out += "\"" + headers[i] + "\":"; out += "\"" + headers[i] + "\":";
out += "\"" + book[i] + "\","; out += "\"" + book[i] + "\",";
} }
// remove the trailing comma
out.pop_back();
return out + "}"; return out + "}";
} }
@ -44,15 +47,18 @@ std::string get_all_books()
// this contains the headers so that we can fill the json file // this contains the headers so that we can fill the json file
header_vec = get_csv_as_vector(line); header_vec = get_csv_as_vector(line);
total_lines = "{"; total_lines = "{ \"books\": [";
while (std::getline(file, line)) { while (std::getline(file, line)) {
book_vec = get_csv_as_vector(line); book_vec = get_csv_as_vector(line);
total_lines += book_vec_to_json(header_vec, book_vec) + ","; total_lines += book_vec_to_json(header_vec, book_vec) + ",";
} }
// remove the trailing comma
total_lines.pop_back();
return total_lines + "}";
return total_lines + "]}";
} }
std::string remove_book(std::string id) std::string remove_book(std::string id)