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

JSON: Add function AddIndent() #182

Closed
AbdealiLoKo opened this issue Oct 31, 2016 · 2 comments
Closed

JSON: Add function AddIndent() #182

AbdealiLoKo opened this issue Oct 31, 2016 · 2 comments

Comments

@AbdealiLoKo
Copy link
Contributor

AbdealiLoKo commented Oct 31, 2016

I've had instances where I would like to first generate a JSON object in one function and then embed this into a array in another JSON object.

In such cases, I do something like:

    dmlc::JSONWriter writer(&os);
    writer.BeginArray();
    for (size_t i = 0; i < dump.size(); ++i) {
      if (i != 0) writer.WriteArraySeperator();
      os << dump[i];  // Dump the previously generated JSON here
    }
    writer.EndArray();

But this means the indenting is not right anymore. Would be nice to be able to fix the indenting with:

    dmlc::JSONWriter writer(&os);
    writer.BeginArray();
    for (size_t i = 0; i < dump.size(); ++i) {
      if (i != 0) writer.WriteArraySeperator();
      os << dmlc::JSONWriter.AddIndent(dump[i], 1);  // Dump the previously generated JSON here
    }
    writer.EndArray();

or something similar

@albanjiang
Copy link

albanjiang commented Feb 27, 2018

👍

@szha
Copy link
Member

szha commented Feb 27, 2018

IMO the JSONWriter shouldn't handle indentation in default setting. The size would be smaller.

@hcho3 hcho3 closed this as completed Oct 7, 2018
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

4 participants