Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why change the default output format #181

Closed
batobolg opened this issue Feb 20, 2015 · 9 comments
Closed

why change the default output format #181

batobolg opened this issue Feb 20, 2015 · 9 comments

Comments

@batobolg
Copy link

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.

@cdunn2001
Copy link
Contributor

Please tell us which commit you are using, and if possible, which commit or version you were using. Also, which Writer are you using?

@batobolg
Copy link
Author

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"
}

@cdunn2001
Copy link
Contributor

What commit/version were you using before, when things worked correctly?

@cdunn2001
Copy link
Contributor

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.

@batobolg
Copy link
Author

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.

@ya1gaurav
Copy link
Contributor

Json::FastWriter can be used to get output in a std::string form.

@batobolg
Copy link
Author

thank you.

@cdunn2001
Copy link
Contributor

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:

@batobolg
Copy link
Author

I am using StreamWriterBuilder plus Json::writeString() , thank you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants