A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
Hi,
I'm trying to serialize an array with the values [0, 2, NaN, NaN] to obtain a JSON Array representation. For this, I have configured the encoder as follow:
` jsoncons::basic_json_options options;
options.nan_to_str("NaN");
options.inf_to_str("Inf");
options.neginf_to_str("NegInf");
m_encoder= new jsoncons::compact_json_stream_encoder(p_io, options);
`
So, I expect the following result: [0, 2, "NaN", "NaN"]. But, the obtained result is [0, 2, "NaN",,"NaN"]. E.g. I have an unexpected comma between the two strings "NaN". Without the options, the result is [0, 2, Null, Null] (no unexpected comma). This difference comes from the way NaN (and also infinities) are managed. Without option (or with the option nan_to_num), visit_double() just add the "Null" string by sink.append. With the option nan_to_str, visit_double() calls visit_string(). Hence visit_string() adds a first comma. And visit_double() adds the second comma.
Hi, I'm trying to serialize an array with the values [0, 2, NaN, NaN] to obtain a JSON Array representation. For this, I have configured the encoder as follow: ` jsoncons::basic_json_options options;
` So, I expect the following result: [0, 2, "NaN", "NaN"]. But, the obtained result is [0, 2, "NaN",,"NaN"]. E.g. I have an unexpected comma between the two strings "NaN". Without the options, the result is [0, 2, Null, Null] (no unexpected comma). This difference comes from the way NaN (and also infinities) are managed. Without option (or with the option nan_to_num), visit_double() just add the "Null" string by sink.append. With the option nan_to_str, visit_double() calls visit_string(). Hence visit_string() adds a first comma. And visit_double() adds the second comma.