diff --git a/src/backend/json.h b/src/backend/json.h index b7252d02..1d3bd107 100644 --- a/src/backend/json.h +++ b/src/backend/json.h @@ -28,6 +28,8 @@ along with LOOT. If not, see #include +#include + namespace loot { // Handy class for turning YAML objects into JSON and vice-versa. @@ -55,6 +57,15 @@ namespace loot { // There's also a bit of weirdness where there are some \x escapes and some \u escapes. // They should all be \u, so transform them. boost::replace_all(json, "\\x", "\\u00"); + // yaml-cpp also emits booleans as "true" and "false" strings, whereas JSON expects the same unquoted basic values. The same happens for null and numbers. + boost::replace_all(json, ": \"true\"", ": true"); + boost::replace_all(json, ": \"false\"", ": false"); + boost::replace_all(json, ": \"null\"", ": null"); + + // Using the definition at . + std::regex numbers(": \"(-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)\"", std::regex::ECMAScript); + + json = std::regex_replace(json, numbers, ": $1"); return json; }