# Class JsonParser (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.JsonParser)
- [3.23.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.JsonParser)
- [3.15.8](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.JsonParser)

    public sealed class JsonParser

Reflection-based converter from JSON to messages.

## Inheritance

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

## 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

## Remarks


Instances of this class are thread-safe, with no mutable state.


This is a simple start to get JSON parsing working. As it's reflection-based,
it's not as quick as baking calls into generated messages - but is a simpler implementation.
(This code is generally not heavily optimized.)

## Constructors

### JsonParser(Settings)

    public JsonParser(JsonParser.Settings settings)

Creates a new formatted with the given settings.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `settings` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParserhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.JsonParser.Settings` The settings. |

## Properties

### Default

    public static JsonParser Default { get; }

Returns a formatter using the default settings.

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

## Methods

### Parse(TextReader, MessageDescriptor)

    public IMessage Parse(TextReader jsonReader, MessageDescriptor descriptor)

Parses JSON read from `jsonReader` into a new message.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `jsonReader` | `https://learn.microsoft.com/dotnet/api/system.io.textreader` Reader providing the JSON to parse. |
| `descriptor` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.MessageDescriptor` Descriptor of message type to parse. |

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

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.InvalidJsonException` | The JSON does not comply with RFC 7159 |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.InvalidProtocolBufferException` | The JSON does not represent a Protocol Buffers message correctly |

### Parse(string, MessageDescriptor)

    public IMessage Parse(string json, MessageDescriptor descriptor)

Parses `json` into a new message.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `json` | `https://learn.microsoft.com/dotnet/api/system.string` The JSON to parse. |
| `descriptor` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.MessageDescriptor` Descriptor of message type to parse. |

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

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.InvalidJsonException` | The JSON does not comply with RFC 7159 |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.InvalidProtocolBufferException` | The JSON does not represent a Protocol Buffers message correctly |

### Parse\<T\>(TextReader)

    public T Parse<T>(TextReader jsonReader) where T : IMessage, new()

Parses JSON read from `jsonReader` into a new message.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `jsonReader` | `https://learn.microsoft.com/dotnet/api/system.io.textreader` Reader providing the JSON to parse. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` |   |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` | The type of message to create. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.InvalidJsonException` | The JSON does not comply with RFC 7159 |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.InvalidProtocolBufferException` | The JSON does not represent a Protocol Buffers message correctly |

### Parse\<T\>(string)

    public T Parse<T>(string json) where T : IMessage, new()

Parses `json` into a new message.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `json` | `https://learn.microsoft.com/dotnet/api/system.string` The JSON to parse. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` |   |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` | The type of message to create. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.InvalidJsonException` | The JSON does not comply with RFC 7159 |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.InvalidProtocolBufferException` | The JSON does not represent a Protocol Buffers message correctly |