Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/standard/serialization/system-text-json-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: "Serialize and deserialize JSON using C# - .NET"
description: This overview describes the System.Text.Json namespace functionality for serializing to and deserializing from JSON in .NET.
ms.date: "01/10/2020"
no-loc: [System.Text.Json, Newtonsoft.Json]
zone_pivot_groups: dotnet-version
helpviewer_keywords:
- "JSON serialization"
- "serializing objects"
Expand Down Expand Up @@ -33,6 +34,27 @@ There are some limitations on what parts of the library that you can use from Vi

For information about security threats that were considered when designing <xref:System.Text.Json.JsonSerializer>, and how they can be mitigated, see [`System.Text.Json` Threat Model](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.Json/docs/ThreatModel.md).

## Thread safety

* The `System.Text.Json` types are thread-safe, including:

:::zone pivot="dotnet-5-0,dotnet-core-3-1"

* <xref:System.Text.Json.JsonSerializer>
* <xref:System.Text.Json.Utf8JsonReader>
* <xref:System.Text.Json.Utf8JsonWriter>
* <xref:System.Text.Json.JsonDocument>
:::zone-end

:::zone pivot="dotnet-6-0"

* <xref:System.Text.Json.JsonSerializer>
* <xref:System.Text.Json.Utf8JsonReader>
* <xref:System.Text.Json.Utf8JsonWriter>
* <xref:System.Text.Json.JsonDocument>
* `JsonNode`
:::zone-end

## Additional resources

* [How to use the library](system-text-json-how-to.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ The preceding code:
* Assumes the JSON to analyze is in a string named `jsonString`.
* Calculates an average grade for objects in a `Students` array that have a `Grade` property.
* Assigns a default grade of 70 for students who don't have a grade.
* Counts students by incrementing a `count` variable with each iteration. An alternative is to call <xref:System.Text.Json.JsonElement.GetArrayLength%2A>, as shown in the following example:
* Creates the `JsonDocument` instance in a [`using` statement](../../csharp/language-reference/keywords/using-statement.md) because `JsonDocument` implements `IDisposable`. After a `JsonDocument` instance is disposed, you lose access to all of its `JsonElement` instances also. To retain access to a `JsonElement` instance, make a copy of it before the parent `JsonDocument` instance is disposed. To make a copy, call <xref:System.Text.Json.JsonElement.Clone%2A?displayProperty=nameWithType>. For more information, see [JsonDocument is IDisposable](system-text-json-migrate-from-newtonsoft-how-to.md#jsondocument-is-idisposable).

The preceding example code counts students by incrementing a `count` variable with each iteration. An alternative is to call <xref:System.Text.Json.JsonElement.GetArrayLength%2A>, as shown in the following example:

:::code language="csharp" source="snippets/system-text-json-how-to/csharp/JsonDocumentDataAccess.cs" id="AverageGrades2":::
:::code language="vb" source="snippets/system-text-json-how-to/vb/JsonDocumentDataAccess.vb" id="AverageGrades2":::
Expand Down