Skip to content

Add to_string overload for indentation #13

Closed

Description

@tanadeau

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

Activity

  1. sillykelvin commented on Jan 6, 2015

    @sillykelvin

    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.

  2. added a commit that references this issue on Jan 6, 2015
  3. nlohmann commented on Jan 6, 2015

    @nlohmann
    Owner

    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.
  4. added a commit that references this issue on May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions