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

Add to_string overload for indentation #13

Closed
tanadeau opened this issue Jan 6, 2015 · 2 comments
Closed

Add to_string overload for indentation #13

tanadeau opened this issue Jan 6, 2015 · 2 comments

Comments

@tanadeau
Copy link

tanadeau commented Jan 6, 2015

Create an overload of the to_string member function that handles indentation (spaces) and line breaks.

const std::string to_string(int indent) const noexcept
@sillykelvin
Copy link

Yeah, I think this is needed when saving a json object to file, it is a great mess if there is no indentation and line breaks.

nlohmann added a commit that referenced this issue Jan 6, 2015
- to_string() method is now called dump()
- syntax borrowed from Python’s json.dumps()
@nlohmann
Copy link
Owner

nlohmann commented Jan 6, 2015

I implemented a pretty-printing serialization. For that, I renamed the function to_string() to dump() and used the syntax of Pythons json.dumps() (see https://docs.python.org/2/library/json.html#json.dump).

This function takes an integer as parameter:

  • If the parameter is -1, no pretty printing is done and the result is the same as before.
  • If the parameter is 0, then newlines are added after elements in arrays and objects.
  • If the parameter is positive, then this number of spaces is used as indentation.

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

No branches or pull requests

3 participants