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

Allows setting of 4 spaces indentation or 2 spaces indentation in JsonSerializerOptions. #1174

Closed
KumoKyaku opened this issue Dec 24, 2019 · 5 comments
Labels
area-System.Text.Json enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@KumoKyaku KumoKyaku changed the title Allows setting of 4 spaces indentation or 2 spaces indentation. Allows setting of 4 spaces indentation or 2 spaces indentation in JsonSerializerOptions. Dec 24, 2019
@danmoseley danmoseley transferred this issue from dotnet/corefx Dec 26, 2019
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Dec 26, 2019
@ahsonkhan
Copy link
Contributor

@KumoKyaku - is this customization required/blocking some scenario or is it just nice to have? Also, are there other "formatting" customization that you would need other than just the 2 spaces vs 4?

To me, since such customization affects the entire JSON stack (serialization and writer), I don't see it worth the potential perf cost, at least on its own. It would help to understand the reason behind such an ask.

@ahsonkhan ahsonkhan added this to the Future milestone Dec 26, 2019
@ahsonkhan ahsonkhan added enhancement Product code improvement that does NOT require public API changes/additions and removed untriaged New issue has not been triaged by the area owner labels Dec 26, 2019
@KumoKyaku
Copy link
Author

Just 4 spaces are easier to read than 2 spaces。

@DaZombieKiller
Copy link
Contributor

Wouldn't it be better to offer something more like this?

public partial class JsonSerializerOptions
{
    /// <summary>The number of spaces to write per indentation level when <see cref="WriteIndented" /> is enabled.</summary>
    public int IndentSpaces { get; set; }
}

@ahsonkhan
Copy link
Contributor

ahsonkhan commented Dec 31, 2019

Wouldn't it be better to offer something more like this?

Agreed. Newtonsoft.Json exposes something like this as well.
https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_Indentation.htm

It also exposes capabilities to customize what char to use (i.e. could use tabs if needed):
https://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonTextWriter_IndentChar.htm

That said, I don't yet see enough evidence that such customization is common enough or necessary for the built-in JSON API which focuses more on perf and most important features over providing all sorts of customizations. To me, this particular request falls in the camp of "keep using Newtonsoft.Json if such a feature/capability is important to your use case", because it isn't worth the trade-off considering the design goals of S.T.Json.

@layomia
Copy link
Contributor

layomia commented Feb 28, 2020

Closing - we don't want to add complexity to the writer to support this feature.

@layomia layomia closed this as completed Feb 28, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

5 participants