forked from kiesraad/eml2sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonhelper.cc
More file actions
32 lines (26 loc) · 741 Bytes
/
jsonhelper.cc
File metadata and controls
32 lines (26 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "sqlwriter.hh"
#include "nlohmann/json.hpp"
using namespace std;
nlohmann::json packResultsJson(const vector<unordered_map<string, MiniSQLite::outvar_t>>& result)
{
nlohmann::json arr = nlohmann::json::array();
for(const auto& row : result) {
nlohmann::json j;
for(auto& col : row) {
std::visit([&j, &col](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, nullptr_t>)
return;
else {
j[col.first] = arg;
}
}, col.second);
}
arr += j;
}
return arr;
}
string packResultsJsonStr(const vector<unordered_map<string, MiniSQLite::outvar_t>>& result)
{
return packResultsJson(result).dump();
}