# Class JsonFormatter.Settings (3.27.1)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [3.27.1 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings)
- [3.23.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.JsonFormatter.Settings)
- [3.15.8](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.JsonFormatter.Settings)

    public sealed class JsonFormatter.Settings

Settings controlling JSON formatting.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> JsonFormatter.Settings

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Protobuf](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf)

## Assembly

Google.Protobuf.dll

## Constructors

### Settings(bool)

    public Settings(bool formatDefaultValues)

Creates a new [JsonFormatter.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified formatting of default
values and an empty type registry.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `formatDefaultValues` | `https://learn.microsoft.com/dotnet/api/system.boolean` `true` if default values (0, empty strings etc) should be formatted; `false` otherwise. |

### Settings(bool, TypeRegistry)

    public Settings(bool formatDefaultValues, TypeRegistry typeRegistry)

Creates a new [JsonFormatter.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified formatting of default
values and type registry.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `formatDefaultValues` | `https://learn.microsoft.com/dotnet/api/system.boolean` `true` if default values (0, empty strings etc) should be formatted; `false` otherwise. |
| `typeRegistry` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.TypeRegistry` The [TypeRegistry](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings#Google_Protobuf_JsonFormatter_Settings_TypeRegistry) to use when formatting [Any](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Any) messages. |

## Properties

### Default

    public static JsonFormatter.Settings Default { get; }

Default settings, as used by [Default](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter#Google_Protobuf_JsonFormatter_Default)

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatterhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings` |   |

### FormatDefaultValues

    public bool FormatDefaultValues { get; }

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).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### FormatEnumsAsIntegers

    public bool FormatEnumsAsIntegers { get; }

Whether to format enums as ints. Defaults to false.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### Indentation

    public string Indentation { get; }

Indentation string, used for formatting. Setting null disables indentation.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### PreserveProtoFieldNames

    public bool PreserveProtoFieldNames { get; }

Whether to use the original proto field names as defined in the .proto file. Defaults to
false.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### TypeRegistry

    public TypeRegistry TypeRegistry { get; }

The type registry used to format [Any](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Any) messages.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.TypeRegistry` |   |

## Methods

### WithFormatDefaultValues(bool)

    public JsonFormatter.Settings WithFormatDefaultValues(bool formatDefaultValues)

Creates a new [JsonFormatter.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified formatting of default
values and the current settings.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `formatDefaultValues` | `https://learn.microsoft.com/dotnet/api/system.boolean` `true` if default values (0, empty strings etc) should be formatted; `false` otherwise. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatterhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings` |   |

### WithFormatEnumsAsIntegers(bool)

    public JsonFormatter.Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers)

Creates a new [JsonFormatter.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified enums formatting option and
the current settings.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `formatEnumsAsIntegers` | `https://learn.microsoft.com/dotnet/api/system.boolean` `true` to format the enums as integers; `false` to format enums as enum names. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatterhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings` |   |

### WithIndentation(string)

    public JsonFormatter.Settings WithIndentation(string indentation = "  ")

Creates a new [JsonFormatter.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified indentation and the current
settings.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `indentation` | `https://learn.microsoft.com/dotnet/api/system.string` The string to output for each level of indentation (nesting). The default is two spaces per level. Use null to disable indentation entirely. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatterhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings` |   |

**Remarks** A non-null value for [Indentation](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings#Google_Protobuf_JsonFormatter_Settings_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](https://learn.microsoft.com/dotnet/api/system.environment.newline), which is `"\n"` on
Unix platforms, and `"\r\n"` on Windows. If [JsonFormatter](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter) seems to
produce empty lines, you need to pass a [TextWriter](https://learn.microsoft.com/dotnet/api/system.io.textwriter) that uses a `"\n"`
newline. See [Format(IMessage, TextWriter)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter#Google_Protobuf_JsonFormatter_Format_Google_Protobuf_IMessage_System_IO_TextWriter_).

### WithPreserveProtoFieldNames(bool)

    public JsonFormatter.Settings WithPreserveProtoFieldNames(bool preserveProtoFieldNames)

Creates a new [JsonFormatter.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified field name formatting
option and the current settings.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `preserveProtoFieldNames` | `https://learn.microsoft.com/dotnet/api/system.boolean` `true` to preserve proto field names; `false` to convert them to lowerCamelCase. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatterhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings` |   |

### WithTypeRegistry(TypeRegistry)

    public JsonFormatter.Settings WithTypeRegistry(TypeRegistry typeRegistry)

Creates a new [JsonFormatter.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings) object with the specified type registry and the
current settings.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `typeRegistry` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.TypeRegistry` The [TypeRegistry](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings#Google_Protobuf_JsonFormatter_Settings_TypeRegistry) to use when formatting [Any](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Any) messages. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatterhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonFormatter.Settings` |   |