342a616a7ff83279e96b01effdeeb7936ace75fb
#include` <iostream>
#include <limits>
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
using namespace rapidjson;
int main ()
{
Document d;
d.SetObject ();
Value v1 (3.14);
double tmp = std::numeric_limits<double>::infinity();
Value v2 (tmp);
Value v3 (345);
d.AddMember ("foo", v1, d.GetAllocator());
d.AddMember ("bar", v2, d.GetAllocator());
d.AddMember ("baz", v3, d.GetAllocator());
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
d.Accept(writer);
std::cout << buffer.GetString() << std::endl;
return 0;
}
writes to stdout:
{"foo":3.14,"bar":
Same issue with signaling_NaN and quiet_NaN.
I don't know if JSON should support +/-Inf and NaN but at least it shouldn't silently stop writing and leaving the generated JSON string useless.
Inf and NaN are not permitted in JSON. The standard says "Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted.".
Did you check the output from d.Accept(writer) ? I guess it will tell you that the writing did not succeed.
You can use kWriteNanAndInfFlag as documented.
For invalid input under the current options, Accept() returns false to indicate failure to write a well-formed JSON.
Most helpful comment
You can use
kWriteNanAndInfFlagas documented.