From 6cbd5a04f8eeafa9860bda26adece2e2ebbfacfc Mon Sep 17 00:00:00 2001 From: Emmanuel Durand Date: Fri, 20 Feb 2026 19:47:13 -0500 Subject: [PATCH] Fix conversion of real numbers from json --- src/utils/jsonutils.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/utils/jsonutils.cpp b/src/utils/jsonutils.cpp index 215c1fe8..d05bc67e 100644 --- a/src/utils/jsonutils.cpp +++ b/src/utils/jsonutils.cpp @@ -346,6 +346,12 @@ bool loadJsonFile(const std::string& filename, Json::Value& configuration) /*************/ Values jsonToValues(const Json::Value& values) { + // When converting from json to values, we start + // by trying to convert to the more complex type + // then we go down. So we start with double, then + // integer and then boolean. This prevents converting + // double to integer by error, for instance when + // handling the value `1.0`. Values outValues; if (values.isBool()) @@ -358,12 +364,12 @@ Values jsonToValues(const Json::Value& values) { for (const auto& v : values) { - if (v.isBool()) - outValues.emplace_back(v.asBool()); + if (v.isDouble()) + outValues.emplace_back(v.asFloat()); else if (v.isInt()) outValues.emplace_back(v.asInt()); - else if (v.isDouble()) - outValues.emplace_back(v.asFloat()); + else if (v.isBool()) + outValues.emplace_back(v.asBool()); else if (v.isArray() || v.isObject()) outValues.emplace_back(jsonToValues(v)); else @@ -376,12 +382,12 @@ Values jsonToValues(const Json::Value& values) int index = 0; for (const auto& v : values) { - if (v.isBool()) - outValues.emplace_back(v.asBool(), names[index]); + if (v.isDouble()) + outValues.emplace_back(v.asFloat(), names[index]); else if (v.isInt()) outValues.emplace_back(v.asInt(), names[index]); - else if (v.isDouble()) - outValues.emplace_back(v.asFloat(), names[index]); + else if (v.isBool()) + outValues.emplace_back(v.asBool(), names[index]); else if (v.isArray() || v.isObject()) outValues.emplace_back(jsonToValues(v), names[index]); else