why change the default output format
Hi ~
I found writer output is changed.
before array output like this.
["aaa","bbb","ccc","ddd"] in one line.
but now it like this.
[
"aaa",
"bbb",
"ccc",
"ddd"
]
why you change it ?.
I like one line format, It not take so much place. if array is too long you can new line by 30 item.
thank you.
Please tell us which commit you are using, and if possible, which commit or version you were using. Also, which Writer are you using?
the version is 1.4.4 and my code like this:
int main(int argc, const char *argv[])
{
Json::Value root;
std::string example = "{\"array\":[\"item1\", \"item2\", \"item2\", \"item2\"], \"foo\":\"asdf\"}";
Json::Reader reader;
bool parsed = reader.parse(example, root, false);
std::cout << root << std::endl;
return 0;
}
+++++++++++++++++++++++ result is:
{
"array" :
[
"item1",
"item2",
"item2",
"item2"
],
"foo" : "asdf"
}
What commit/version were you using before, when things worked correctly?
I assume you were using the 0.6.0-rc2 version, or something fairly old, right?
Instead of
std::cout << root << std::endl;
try
Json::StreamWriterBuilder builder;
builder.settings_["commentStyle"] = "None"; // default is "All"
cout << Json::writeString(builder, root);
The reason for the change is that // this kind of comment cannot be embedded on a single line. Test-cases were failing with the old, but they had been suppressed instead of fixed. The choices were:
- A) Keep the old, weird, inconsistent behavior for embedded comments.
- Very hard to maintain, let alone document and explain.
- B) Leave comments off by default.
- Likely to break lots of users.
- C) Leave comments on by default.
- Might upset a few users, but it should not actually break anyone. And the work-around is simple.
Sorry. I hope the work-around is ok.
the header file shows #define JSONCPP_VERSION_STRING "1.4.4"
work-around is ok , yes. I like it. thank you, thank you very much.
Json::FastWriter can be used to get output in a std::string form.
thank you.
I wouldn't recommend FastWriter. Because its internals are exposed, we cannot alter that class and maintain binary-compatibility. That makes it hard to support.
I suggest StreamWriterBuilder plus Json::writeString(), as shown under Advanced Usage here:
- http://open-source-parsers.github.io/jsoncpp-docs/doxygen/index.html
I am using StreamWriterBuilder plus Json::writeString() , thank you. :)