1111#include < villas/config.hpp>
1212#include < villas/exceptions.hpp>
1313#include < villas/hist.hpp>
14+ #include < villas/jansson.hpp>
1415#include < villas/table.hpp>
1516#include < villas/utils.hpp>
1617
@@ -203,15 +204,24 @@ char *Hist::dump() const {
203204json_t *Hist::toJson () const {
204205 json_t *json_buckets, *json_hist;
205206
206- json_hist = json_pack (" { s: f, s: f, s: i }" , " low" , low, " high" , high,
207- " total" , total);
207+ json_hist = janssonPack (" { s:f, s:f, s:I }" , //
208+ " low" , low, //
209+ " high" , high, //
210+ " total" , static_cast <json_int_t >(total))
211+ .release ();
208212
209213 if (total > 0 ) {
210- json_object_update (json_hist,
211- json_pack (" { s: i, s: i, s: f, s: f, s: f, s: f, s: f }" ,
212- " higher" , higher, " lower" , lower, " highest" ,
213- highest, " lowest" , lowest, " mean" , getMean (),
214- " variance" , getVar (), " stddev" , getStddev ()));
214+ json_object_update_new (
215+ json_hist,
216+ janssonPack (" { s:I, s:I, s:f, s:f, s:f, s:f, s:f }" , //
217+ " higher" , static_cast <json_int_t >(higher), //
218+ " lower" , static_cast <json_int_t >(lower), //
219+ " highest" , highest, //
220+ " lowest" , lowest, //
221+ " mean" , getMean (), //
222+ " variance" , getVar (), //
223+ " stddev" , getStddev ())
224+ .release ());
215225 }
216226
217227 if (total - lower - higher > 0 ) {
@@ -220,7 +230,7 @@ json_t *Hist::toJson() const {
220230 for (auto elm : data)
221231 json_array_append (json_buckets, json_integer (elm));
222232
223- json_object_set (json_hist, " buckets" , json_buckets);
233+ json_object_set_new (json_hist, " buckets" , json_buckets);
224234 }
225235
226236 return json_hist;
0 commit comments