Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

JSON serialization and deserialization in .NET - overview

  • 2025-01-29
Feedback

In this article

TheSystem.Text.Json namespace provides functionality for serializing to and deserializing from (or marshalling and unmarshalling) JavaScript Object Notation (JSON).Serialization is the process of converting the state of an object, that is, the values of its properties, into a form that can be stored or transmitted. The serialized form doesn't include any information about an object's associated methods.Deserialization reconstructs an object from the serialized form.

TheSystem.Text.Json library design emphasizes high performance and low memory allocation over an extensive feature set. Built-in UTF-8 support optimizes the process of reading and writing JSON text encoded as UTF-8, which is the most prevalent encoding for data on the web and files on disk.

The library also provides classes for working with an in-memorydocument object model (DOM). This feature enables random access to the elements in a JSON file or string.

For Visual Basic, there are some limitations on what parts of the library you can use. For more information, seeVisual Basic support.

How to get the library

The library is built-in as part of the shared framework for .NET Core 3.0 and later versions. Thesource generation feature is built-in as part of the shared framework for .NET 6 and later versions.

For framework versions earlier than .NET Core 3.0, install theSystem.Text.Json NuGet package. The package supports:

  • .NET Standard 2.0 and later
  • .NET Framework 4.6.2 and later
  • .NET 8 and later

Namespaces and APIs

Important

System.Text.Json doesn't support the following serialization APIs that you might have used previously:

Reflection vs. source generation

By default,System.Text.Json gathers the metadata it needs to access properties of objects for serialization and deserializationat run time usingreflection. As an alternative,System.Text.Json can use the C#source generation feature to improve performance, reduce private memory usage, and facilitateassembly trimming, which reduces app size.

For more information, seeReflection versus source generation.

Security information

For information about security threats that were considered when designingJsonSerializer, and how they can be mitigated, seeSystem.Text.Json Threat Model.

Thread safety

TheSystem.Text.Json serializer was designed with thread safety in mind. Practically, this means that once locked,JsonSerializerOptions instances can be safely shared across multiple threads.JsonDocument provides an immutable, and in .NET 8 and later versions, thread-safe, DOM representation for JSON values.

Additional resources

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo