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 whitespaceOptions: colonBraceSameLine to settings #1337

Closed

Conversation

NotWearingPants
Copy link
Contributor

@NotWearingPants NotWearingPants commented Oct 2, 2021

Fixes #1336 by adding an array option called "whitespaceOptions" to StreamWriterBuilder, and a possible value called "colonBraceSameLine" which causes { and [ following a colon to be placed in the same line.
The option is backed by a flag enum in BuiltStyledStreamWriter.

Example usage:

Json::StreamWriterBuilder builder;
builder.settings_["whitespaceOptions"] = Json::Value { Json::ValueType::arrayValue };
builder.settings_["whitespaceOptions"].append("colonBraceSameLine");

Json::Value json { Json::ValueType::objectValue };
json["hello"] = Json::Value { Json::ValueType::objectValue };
json["hello"]["world"] = "!";
json["world"] = Json::Value { Json::ValueType::arrayValue };
json["world"].append("!");

std::cout << Json::writeString(builder, json) << std::endl;

Result:

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

@cdunn2001
Copy link
Contributor

I like this. Thanks. Could use a test though.

Does anyone else have time to review this?

@baylesj
Copy link
Contributor

baylesj commented Dec 15, 2021

I'd be happy to review once there is test coverage associated with this.

include/json/value.h Outdated Show resolved Hide resolved
@NotWearingPants
Copy link
Contributor Author

Rebased and fixed review comment

@baylesj
Copy link
Contributor

baylesj commented Sep 12, 2024

This needs to be formatted and have tests added.

Closing this due to inactivity. Feel free to reopen if you are able to address feedback.

@baylesj baylesj closed this Sep 12, 2024
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

Successfully merging this pull request may close these issues.

Braces/brackets on the same line
4 participants