diff --git a/json11.cpp b/json11.cpp index 34f9098..0aa125b 100644 --- a/json11.cpp +++ b/json11.cpp @@ -21,6 +21,7 @@ #include "json11.hpp" #include +#include #include #include #include @@ -45,9 +46,13 @@ static void dump(std::nullptr_t, string &out) { } static void dump(double value, string &out) { - char buf[32]; - snprintf(buf, sizeof buf, "%.17g", value); - out += buf; + if (std::isfinite(value)) { + char buf[32]; + snprintf(buf, sizeof buf, "%.17g", value); + out += buf; + } else { + out += "null"; + } } static void dump(int value, string &out) {