Whether fields which would otherwise not be included in the formatted data
should be formatted even when the value is not present, or has the default value.
This option only affects fields which don't support "presence" (e.g.
singular non-optional proto3 primitive fields).
A non-null value for Indentation will insert additional line-breaks
to the JSON output. Each line will contain either a single value, or braces. The default
line-break is determined by NewLine, which is "\n" on
Unix platforms, and "\r\n" on Windows. If JsonFormatter seems to
produce empty lines, you need to pass a TextWriter that uses a "\n"
newline. See Format(IMessage, TextWriter).
WithPreserveProtoFieldNames(bool)
public JsonFormatter.Settings WithPreserveProtoFieldNames(bool preserveProtoFieldNames)
Creates a new JsonFormatter.Settings object with the specified field name formatting
option and the current settings.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003e\u003ccode\u003eJsonFormatter.Settings\u003c/code\u003e controls how JSON data is formatted, including the handling of default values, type registries, and indentation.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize settings for JSON formatting, such as whether default values and enums are included, or whether to preserve proto field names, all of which are detailed in the properties.\u003c/p\u003e\n"],["\u003cp\u003eConstructors allow you to create \u003ccode\u003eJsonFormatter.Settings\u003c/code\u003e with options for formatting default values and the use of a type registry for messages, such as \u003ccode\u003eAny\u003c/code\u003e messages.\u003c/p\u003e\n"],["\u003cp\u003eSeveral methods are provided to create new \u003ccode\u003eJsonFormatter.Settings\u003c/code\u003e objects with modified options, maintaining the current settings, such as \u003ccode\u003eWithFormatDefaultValues\u003c/code\u003e, \u003ccode\u003eWithIndentation\u003c/code\u003e, \u003ccode\u003eWithPreserveProtoFieldNames\u003c/code\u003e, \u003ccode\u003eWithFormatEnumsAsIntegers\u003c/code\u003e and \u003ccode\u003eWithTypeRegistry\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDefault\u003c/code\u003e property provides the default settings used by \u003ccode\u003eJsonFormatter\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Class JsonFormatter.Settings (3.27.1)\n\nVersion latestkeyboard_arrow_down\n\n- [3.27.1 (latest)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings)\n- [3.23.0](/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.JsonFormatter.Settings)\n- [3.15.8](/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.JsonFormatter.Settings) \n\n public sealed class JsonFormatter.Settings\n\nSettings controlling JSON formatting. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e JsonFormatter.Settings \n\nInherited Members\n-----------------\n\n[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) \n[object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) \n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Protobuf](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf)\n\nAssembly\n--------\n\nGoogle.Protobuf.dll\n\nConstructors\n------------\n\n### Settings(bool)\n\n public Settings(bool formatDefaultValues)\n\nCreates a new [JsonFormatter.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified formatting of default\nvalues and an empty type registry.\n\n### Settings(bool, TypeRegistry)\n\n public Settings(bool formatDefaultValues, TypeRegistry typeRegistry)\n\nCreates a new [JsonFormatter.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified formatting of default\nvalues and type registry.\n\nProperties\n----------\n\n### Default\n\n public static JsonFormatter.Settings Default { get; }\n\nDefault settings, as used by [Default](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter#Google_Protobuf_JsonFormatter_Default)\n\n### FormatDefaultValues\n\n public bool FormatDefaultValues { get; }\n\nWhether fields which would otherwise not be included in the formatted data\nshould be formatted even when the value is not present, or has the default value.\nThis option only affects fields which don't support \"presence\" (e.g.\nsingular non-optional proto3 primitive fields).\n\n### FormatEnumsAsIntegers\n\n public bool FormatEnumsAsIntegers { get; }\n\nWhether to format enums as ints. Defaults to false.\n\n### Indentation\n\n public string Indentation { get; }\n\nIndentation string, used for formatting. Setting null disables indentation.\n\n### PreserveProtoFieldNames\n\n public bool PreserveProtoFieldNames { get; }\n\nWhether to use the original proto field names as defined in the .proto file. Defaults to\nfalse.\n\n### TypeRegistry\n\n public TypeRegistry TypeRegistry { get; }\n\nThe type registry used to format [Any](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Any) messages.\n\nMethods\n-------\n\n### WithFormatDefaultValues(bool)\n\n public JsonFormatter.Settings WithFormatDefaultValues(bool formatDefaultValues)\n\nCreates a new [JsonFormatter.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified formatting of default\nvalues and the current settings.\n\n### WithFormatEnumsAsIntegers(bool)\n\n public JsonFormatter.Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers)\n\nCreates a new [JsonFormatter.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified enums formatting option and\nthe current settings.\n\n### WithIndentation(string)\n\n public JsonFormatter.Settings WithIndentation(string indentation = \" \")\n\nCreates a new [JsonFormatter.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified indentation and the current\nsettings.\n\n**Remarks** \nA non-null value for [Indentation](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings#Google_Protobuf_JsonFormatter_Settings_Indentation) will insert additional line-breaks\nto the JSON output. Each line will contain either a single value, or braces. The default\nline-break is determined by [NewLine](https://learn.microsoft.com/dotnet/api/system.environment.newline), which is `\"\\n\"` on\nUnix platforms, and `\"\\r\\n\"` on Windows. If [JsonFormatter](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter) seems to\nproduce empty lines, you need to pass a [TextWriter](https://learn.microsoft.com/dotnet/api/system.io.textwriter) that uses a `\"\\n\"`\nnewline. See [Format(IMessage, TextWriter)](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter#Google_Protobuf_JsonFormatter_Format_Google_Protobuf_IMessage_System_IO_TextWriter_).\n\n### WithPreserveProtoFieldNames(bool)\n\n public JsonFormatter.Settings WithPreserveProtoFieldNames(bool preserveProtoFieldNames)\n\nCreates a new [JsonFormatter.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified field name formatting\noption and the current settings.\n\n### WithTypeRegistry(TypeRegistry)\n\n public JsonFormatter.Settings WithTypeRegistry(TypeRegistry typeRegistry)\n\nCreates a new [JsonFormatter.Settings](/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified type registry and the\ncurrent settings."]]