I'm using jsoncpp and I'm having a problem with how the json messages are formatted when they are written using one of the Writers.
For example:
root["name"] = "monkey";
std::cout << writer.write(root) << "\n";
Gives me something formatted like this
{
"name" : "monkey"
}
While I actually want:
{"name":"monkey"}
I've looked at the documentation and there are mentions of setIndentLength()
but they don't appear in the source files, so maybe they are deprecated or something.
Anyway anyone knows how to do this?
As an extension of cdunn2001's answer, there is no need to re-write default settings (.settings_). You can just override 'indentation' value of StreamWriterBuilder builder:
Json::Value json = ...
Json::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = ""; //The JSON document is written in a single line
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
writer->write(json, &std::cout);
If you use Jsoncpp version 1.1, you can use Json::FastWriter
instead of Json::StyledWriter
or Json::Writer
:
The JSON document is written in a single line. It is not intended for 'human' consumption, but may be usefull to support feature such as RPC where bandwith is limited.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With