-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Comments
@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. |
Just 4 spaces are easier to read than 2 spaces。 |
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; }
} |
Agreed. Newtonsoft.Json exposes something like this as well. It also exposes capabilities to customize what char to use (i.e. could use tabs if needed): 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 |
Closing - we don't want to add complexity to the writer to support this feature. |
https://github.com/dotnet/corefx/blob/e99ec129cfd594d53f4390bf97d1d736cff6f860/src/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs#L15
The text was updated successfully, but these errors were encountered: