Skip to content

Braces/brackets on the same line #1336

Open
@NotWearingPants

Description

@NotWearingPants

Is your feature request related to a problem? Please describe.
When printing JSON (std::cout << json, StreamWriterBuilder+BuiltStyledStreamWriter), if an object contains another object or an array, it looks like this:

{
	"hello" : 
	{
		"world" : "!"
	},
	"world" : 
	[
		"!"
	]
}

while I want it to look like this:

{
	"hello" : {
		"world" : "!"
	},
	"world" : [
		"!"
	]
}

Also, currently there's trailing whitespace after the colons which is annoying.

Describe the solution you'd like
To solve both problems at once, whenever the opening { or [ of an object or array is printed after a colon of an object key:value pair, I want it to not move to a new line and indent and instead print it in the same line.

Describe alternatives you've considered
I've considered solving the trailing whitespace problem while keeping the brace/bracket the way it is, but it's easier this way and I prefer it.

Additional context
I think a setting should be added to StreamWriterBuilder called something like whitespaceStyle, and currently have two options: colonBracesOnNewLine and colonBracesOnSameLine.

This way instead of a boolean setting, in the future maybe one can add whitespaceStyle: leftComma for example, for this:

{
	"foo": "bar"
	, "hello": "world"
	, "this is": "weird"
}

I'm wondering whether combining values should be possible or not, for example using both colonBracesOnSameLine and leftComma at the same time, so maybe whitespaceStyle can be an array. Or separate boolean flags. Not sure.

More future options for whitespaceStyle:
minimal to output the JSON as compactly as possible without any spaces.
commaBracesOnSameLine/bracketBraceOnSameLine for having { be on the same line as a preceding ,/[ respectively.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions