{"id":23568,"date":"2019-06-13T10:39:05","date_gmt":"2019-06-13T17:39:05","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=23568"},"modified":"2021-09-29T12:16:43","modified_gmt":"2021-09-29T19:16:43","slug":"try-the-new-system-text-json-apis","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/try-the-new-system-text-json-apis\/","title":{"rendered":"Try the new System.Text.Json APIs"},"content":{"rendered":"<p>For .NET Core 3.0, we&#8217;re shipping a brand new namespace called\u00a0<a href=\"https:\/\/nuget.org\/packages\/System.Text.Json\" rel=\"nofollow\">System.Text.Json<\/a>\u00a0with support for a reader\/writer, a document object model (DOM), and a serializer. In this blog post, I&#8217;m telling you why we built it, how it works, and how you can try it.<\/p>\n<p>We also have a video:<\/p>\n<p><iframe src=\"https:\/\/channel9.msdn.com\/Shows\/On-NET\/Try-the-new-SystemTextJson-APIs\/player\" width=\"550\" height=\"310\" allowFullScreen frameBorder=\"0\"><\/iframe><\/p>\n<h2><a id=\"user-content-getting-the-new-json-library\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#getting-the-new-json-library\" aria-hidden=\"true\"><\/a>Getting the new JSON library<\/h2>\n<ul>\n<li><strong>If you&#8217;re targeting .NET Core<\/strong>. Install the latest version of the\u00a0<a href=\"https:\/\/dotnet.microsoft.com\/download\/dotnet-core\/3.0\" rel=\"nofollow\">.NET Core 3.0 preview<\/a>. This gives you the new JSON library and the ASP.NET Core integration.<\/li>\n<li><strong>If you&#8217;re targeting .NET Standard or .NET Framework<\/strong>. Install the\u00a0<a href=\"https:\/\/nuget.org\/packages\/System.Text.Json\" rel=\"nofollow\">System.Text.Json<\/a>\u00a0NuGet package (make sure to include previews and install version 4.6.0-preview6.19303.8 or higher). In order to get the integration with ASP.NET Core, you must target .NET Core 3.0.<\/li>\n<\/ul>\n<h2><a id=\"user-content-the-future-of-json-in-net-core-30\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#the-future-of-json-in-net-core-30\" aria-hidden=\"true\"><\/a>The future of JSON in .NET Core 3.0<\/h2>\n<p>JSON has become an essential part of virtually all modern .NET applications and in many cases even surpassed the usage of XML. However, .NET hasn&#8217;t had a (great) built-in way to deal with JSON. Instead, we&#8217;ve relied on Json.NET until now, which continues to serve the .NET ecosystem well.<\/p>\n<p>We&#8217;ve decided that we needed to build a new JSON library:<\/p>\n<ul>\n<li><strong>Provide high-performance JSON APIs<\/strong>. We needed a new set of JSON APIs that are highly tuned for performance by using\u00a0<code>Span&lt;T&gt;<\/code>\u00a0and can process UTF-8 directly without having to transcode to UTF-16\u00a0<code>string<\/code>\u00a0instances. Both aspects are critical for ASP.NET Core, where throughput is a key requirement. We considered contributing changes to Json.NET, but this was deemed close to impossible without either breaking existing Json.NET customers or compromising on the performance we could achieve. With\u00a0<code>System.Text.Json<\/code>, we were able to gain 1.3x &#8211; 5x speed up, depending on the scenario (see below for more details). And we believe we can still squeeze out more.<\/li>\n<li><strong>Remove Json.NET dependency from ASP.NET Core<\/strong>. Today, ASP.NET Core has a dependency on Json.NET. While this provides a tight integration between ASP.NET Core and Json.NET, it also means the version of Json.NET is dictated by the underlying platform. However, Json.NET is frequently updated and application developers often want to &#8212; or even have to &#8212; use a specific version. Thus, we want to remove the Json.NET dependency from ASP.NET Core 3.0, so that customers can choose which version to use, without fearing they might accidentally break the underlying platform.<\/li>\n<li><strong>Provide an ASP.NET Core integration package for Json.NET<\/strong>. Json.NET has basically become the Swiss Army knife of JSON processing in .NET. It provides many options and facilities that allow customers to handle their JSON needs with ease. We don&#8217;t want to compromise on the Json.NET support customers are getting today. For example, the ability to configure the JSON serialization in ASP.NET Core via the\u00a0<code>AddJsonOptions<\/code>\u00a0extension method. Thus, we want to provide the Json.NET integration for ASP.NET Core as a NuGet package that developers can optionally install, so they get all the bells and whistles they get from Json.NET today. The other part of this work item is to ensure we have the right extension points so that other parties can provide similar integration packages for their JSON library of choice.<\/li>\n<\/ul>\n<p>For more details on the motivation and how it relates to Json.NET, take a look at\u00a0<a href=\"https:\/\/github.com\/dotnet\/corefx\/issues\/33115\">the announcement<\/a>\u00a0we made back in October.<\/p>\n<h2><a id=\"user-content-using-systemtextjson-directly\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#using-systemtextjson-directly\" aria-hidden=\"true\"><\/a>Using System.Text.Json directly<\/h2>\n<p>For all the samples, make sure you import the following two namespaces:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/7b5e43f8cbf2caa0a469e140ba1067ed.js\"><\/script><\/p>\n<h3><a id=\"user-content-using-the-serializer\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#using-the-serializer\" aria-hidden=\"true\"><\/a>Using the serializer<\/h3>\n<p>The\u00a0<code>System.Text.Json<\/code>\u00a0serializer can read and write JSON asynchronously and is optimized for UTF-8 text, making it ideal for REST API and back-end applications.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/985e1d5143c0b4aef21c6e40229592c7.js\"><\/script><\/p>\n<p>By default, we produce minified JSON. If you want to produce something that is human readable, you can pass in an instance of\u00a0<code>JsonSerializerOptions<\/code>\u00a0to the serializer. This is also the way you configure other settings, such as handling of comments, trailing commas, and naming policies.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/42ec86ea4c9a36327ddd4489dfa8292c.js\"><\/script><\/p>\n<p>Deserialization works similarly:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/ca3efddcbcd37c0b621cc7408f265e8b.js\"><\/script><\/p>\n<p>We also support asynchronous serialization and deserialization:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/5fafc6234fe0b8fd0a783b5c08357f7f.js\"><\/script><\/p>\n<p>You can also use custom attributes to control serialization behavior, for example, ignoring properties and specifying the name of the property in the JSON:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/3b41d911ad2516b309c3fe206c0084a4.js\"><\/script><\/p>\n<p>We currently don&#8217;t have support for F# specific behaviors (such as discriminated unions and record types), but we\u00a0<a href=\"https:\/\/github.com\/dotnet\/corefx\/issues\/38348\">plan on adding this in the future<\/a>.<\/p>\n<h3><a id=\"user-content-using-the-dom\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#using-the-dom\" aria-hidden=\"true\"><\/a>Using the DOM<\/h3>\n<p>Sometimes you don&#8217;t want to deserialize a JSON payload, but you still want structured access to its contents. For example, let&#8217;s say we have a collection of temperatures and want to average out the temperatures on Mondays:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/2e7aafea29a9ac5acf9c0c18f5ff0c5a.js\"><\/script><\/p>\n<p>The\u00a0<a href=\"https:\/\/docs.microsoft.com\/dotnet\/api\/system.text.json.jsondocument\" rel=\"nofollow\">JsonDocument<\/a>\u00a0class allows you to access the individual properties and values quite easily.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/a1e707f1652347ca8e715925f62beb90.js\"><\/script><\/p>\n<h3><a id=\"user-content-using-the-writer\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#using-the-writer\" aria-hidden=\"true\"><\/a>Using the writer<\/h3>\n<p>The writer is straight forward to use:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/336da6ae0a327bef113c1325710164f0.js\"><\/script><\/p>\n<p>The reader requires you to switch on the token type:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/1abe442a54cc6dc18ca9f7e8f0a45a64.js\"><\/script><\/p>\n<h2><a id=\"user-content-integration-with-aspnet-core\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#integration-with-aspnet-core\" aria-hidden=\"true\"><\/a>Integration with ASP.NET Core<\/h2>\n<p>Most use of JSON inside of ASP.NET Core is provided via the automatic serialization when accepting or returning object payloads, which in turn means that most of your application&#8217;s code is agnostic to which JSON library ASP.NET Core is using. That makes it easy to switch from one to another.<\/p>\n<p>You can see the details on how you can enable the new JSON library in MVC and SignalR later on in this post.<\/p>\n<h3><a id=\"user-content-integration-with-aspnet-core-mvc\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#integration-with-aspnet-core-mvc\" aria-hidden=\"true\"><\/a>Integration with ASP.NET Core MVC<\/h3>\n<p>In Preview 5, ASP.NET Core MVC added support for reading and writing JSON using\u00a0<code>System.Text.Json<\/code>. Starting with Preview 6, the new JSON library is used by default for serializing and deserializing JSON payloads.<\/p>\n<p>Options for the serializer can be configured using\u00a0<a href=\"https:\/\/docs.microsoft.com\/dotnet\/api\/microsoft.aspnetcore.mvc.mvcoptions\" rel=\"nofollow\">MvcOptions<\/a>:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/terrajobst\/dd66982467fcca2a525e333f3ac6e377.js\"><\/script><\/p>\n<p>If you&#8217;d like to switch back to the previous default of using\u00a0<code>Newtonsoft.Json<\/code>, do the following:<\/p>\n<ol>\n<li>Install the\u00a0<a href=\"https:\/\/nuget.org\/packages\/Microsoft.AspNetCore.Mvc.NewtonsoftJson\" rel=\"nofollow\">Microsoft.AspNetCore.Mvc.NewtonsoftJson<\/a>\u00a0NuGet package.<\/li>\n<li>In\u00a0<code>ConfigureServices()<\/code>\u00a0add a call to\u00a0<code>AddNewtonsoftJson()<\/code>\n<script src=\"https:\/\/gist.github.com\/terrajobst\/c1f29bd6e66ae54d26d872904ba38ed4.js\"><\/script><\/li>\n<\/ol>\n<p><strong>Known issues<\/strong><\/p>\n<ul>\n<li>Support for\u00a0<a href=\"https:\/\/docs.microsoft.com\/aspnet\/core\/tutorials\/web-api-help-pages-using-swagger\" rel=\"nofollow\">OpenAPI \/ Swagger<\/a>\u00a0when using\u00a0<code>System.Text.Json<\/code>\u00a0is ongoing and unlikely to be available as part of the 3.0 release.<\/li>\n<\/ul>\n<h3><a id=\"user-content-integration-with-signalr\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#integration-with-signalr\" aria-hidden=\"true\"><\/a>Integration with SignalR<\/h3>\n<p><code>System.Text.Json<\/code>\u00a0is now the default Hub Protocol used by SignalR clients and servers starting in ASP.NET Core 3.0 Preview 5.<\/p>\n<p>If you&#8217;d like to switch back to the previous default of using\u00a0<code>Newtonsoft.Json<\/code>, then you can do so on both the client and server.<\/p>\n<ol>\n<li>Install the\u00a0<code>Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson<\/code>\u00a0NuGet package.<\/li>\n<li>On the client add\u00a0<code>.AddNewtonsoftJsonProtocol()<\/code>\u00a0to the\u00a0<code>HubConnectionBuilder<\/code>:\n<script src=\"https:\/\/gist.github.com\/terrajobst\/d7331fabd39c0e19cfcb849c279b708d.js\"><\/script><\/li>\n<li>On the server add\u00a0<code>.AddNewtonsoftJsonProtocol()<\/code>\u00a0to the\u00a0<code>AddSignalR()<\/code>\u00a0call:\n<script src=\"https:\/\/gist.github.com\/terrajobst\/95bc900a81c5542d25e140bed4bf4ac5.js\"><\/script><\/li>\n<\/ol>\n<h2><a id=\"user-content-performance\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#performance\" aria-hidden=\"true\"><\/a>Performance<\/h2>\n<p>Since this feature is heavily motivated by performance, we&#8217;d like to share some high-level performance characteristics of the new APIs.<\/p>\n<p>Please keep in mind that these are based on preview builds and the final numbers will most likely differ. We&#8217;re also still tweaking default behaviors which will affect performance (for example, case sensitivity). Please note that these are micro benchmarks. Your mileage will most certainly differ, so if performance is critical for you, make sure to make your own measurements for scenarios that best represent your workload. If you encounter scenarios you&#8217;d like us to optimize further,\u00a0<a href=\"https:\/\/github.com\/dotnet\/corefx\/issues\/new\">please file a bug<\/a>.<\/p>\n<h3><a id=\"user-content-raw-systemtextjson\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#raw-systemtextjson\" aria-hidden=\"true\"><\/a>Raw System.Text.Json<\/h3>\n<p>Just doing micro benchmarks to compare\u00a0<code>System.Text.Json<\/code>\u00a0with Json.NET yields the following output:<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"left\">Scenario<\/th>\n<th align=\"left\">Speed<\/th>\n<th align=\"left\">Memory<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\"><strong>Deserialization<\/strong><\/td>\n<td align=\"left\">2x faster<\/td>\n<td align=\"left\">Parity or lower<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><strong>Serialization<\/strong><\/td>\n<td align=\"left\">1.5x faster<\/td>\n<td align=\"left\">Parity or lower<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><strong>Document<\/strong>\u00a0(read-only)<\/td>\n<td align=\"left\">3-5x faster<\/td>\n<td align=\"left\">~Allocation free for sizes &lt; 1 MB<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><strong>Reader<\/strong><\/td>\n<td align=\"left\">2-3x faster<\/td>\n<td align=\"left\">~Allocation free (until you materialize values)<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><strong>Writer<\/strong><\/td>\n<td align=\"left\">1.3-1.6x faster<\/td>\n<td align=\"left\">~Allocation free<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3><a id=\"user-content-systemtextjson-in-aspnet-core-mvc\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#systemtextjson-in-aspnet-core-mvc\" aria-hidden=\"true\"><\/a>System.Text.Json in ASP.NET Core MVC<\/h3>\n<p>We&#8217;ve written an ASP.NET Core app that generates\u00a0<a href=\"https:\/\/github.com\/aspnet\/Benchmarks\/blob\/5beb0cccac53a32dda42cf29686efeb732a1e5d1\/src\/Benchmarks\/Controllers\/HomeController.cs#L18-L35\">data on the fly<\/a>\u00a0that is then serialized and deserialized from\u00a0<a href=\"https:\/\/github.com\/aspnet\/Benchmarks\/blob\/5beb0cccac53a32dda42cf29686efeb732a1e5d1\/src\/Benchmarks\/Controllers\/HomeController.cs#L42-L55\">MVC controllers<\/a>. We then varied the payload sizes and measured the results:<\/p>\n<p><strong>JSON deserialization (input)<\/strong><\/p>\n<table style=\"height: 182px; width: 483px;\" cellpadding=\"0px 10px 0px 10px\">\n<thead>\n<tr style=\"height: 26px;\">\n<th style=\"height: 26px; width: 204px; text-align: left;\" align=\"right\">Description<\/th>\n<th style=\"height: 26px; width: 85px; text-align: right;\" align=\"right\">RPS<\/th>\n<th style=\"height: 26px; width: 78px; text-align: right;\" align=\"right\">CPU (%)<\/th>\n<th style=\"height: 26px; width: 115px; text-align: right;\" align=\"right\">Memory (MB)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 204px; text-align: left;\" align=\"right\"><code>Newtonsoft.Json<\/code>\u00a0&#8211; 500 B<\/td>\n<td style=\"height: 26px; width: 85px; text-align: right;\" align=\"right\">136,435<\/td>\n<td style=\"height: 26px; width: 78px; text-align: right;\" align=\"right\">95<\/td>\n<td style=\"height: 26px; width: 115px; text-align: right;\" align=\"right\">172<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 204px; text-align: left;\" align=\"right\"><code>System.Text.Json<\/code>\u00a0&#8211; 500 B<\/td>\n<td style=\"height: 26px; width: 85px; text-align: right;\" align=\"right\">167,861<\/td>\n<td style=\"height: 26px; width: 78px; text-align: right;\" align=\"right\">94<\/td>\n<td style=\"height: 26px; width: 115px; text-align: right;\" align=\"right\">169<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 204px; text-align: left;\" align=\"right\"><code>Newtonsoft.Json<\/code>\u00a0&#8211; 2.4 KB<\/td>\n<td style=\"height: 26px; width: 85px; text-align: right;\" align=\"right\">97,137<\/td>\n<td style=\"height: 26px; width: 78px; text-align: right;\" align=\"right\">97<\/td>\n<td style=\"height: 26px; width: 115px; text-align: right;\" align=\"right\">174<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 204px; text-align: left;\" align=\"right\"><code>System.Text.Json<\/code>\u00a0&#8211; 2.4 KB<\/td>\n<td style=\"height: 26px; width: 85px; text-align: right;\" align=\"right\">132,026<\/td>\n<td style=\"height: 26px; width: 78px; text-align: right;\" align=\"right\">96<\/td>\n<td style=\"height: 26px; width: 115px; text-align: right;\" align=\"right\">169<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 204px; text-align: left;\" align=\"right\"><code>Newtonsoft.Json<\/code>\u00a0&#8211; 40 KB<\/td>\n<td style=\"height: 26px; width: 85px; text-align: right;\" align=\"right\">7,712<\/td>\n<td style=\"height: 26px; width: 78px; text-align: right;\" align=\"right\">88<\/td>\n<td style=\"height: 26px; width: 115px; text-align: right;\" align=\"right\">212<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"height: 26px; width: 204px; text-align: left;\" align=\"right\"><code>System.Text.Json<\/code>\u00a0&#8211; 40 KB<\/td>\n<td style=\"height: 26px; width: 85px; text-align: right;\" align=\"right\">16,625<\/td>\n<td style=\"height: 26px; width: 78px; text-align: right;\" align=\"right\">96<\/td>\n<td style=\"height: 26px; width: 115px; text-align: right;\" align=\"right\">193<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><strong>JSON serialization (output)<\/strong><\/p>\n<table style=\"width: 480px; height: 182px;\" cellpadding=\"0px 10px 0px 10px\">\n<thead>\n<tr style=\"height: 26px;\">\n<th style=\"width: 202px; text-align: left; height: 26px;\" align=\"right\">Description<\/th>\n<th style=\"text-align: right; width: 85px; height: 26px;\" align=\"right\">RPS<\/th>\n<th style=\"text-align: right; width: 80px; height: 26px;\" align=\"right\">CPU (%)<\/th>\n<th style=\"text-align: right; width: 112px; height: 26px;\" align=\"right\">Memory (MB)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"height: 26px;\">\n<td style=\"width: 202px; text-align: left; height: 26px;\" align=\"right\"><code>Newtonsoft.Json<\/code>\u00a0&#8211; 500 B<\/td>\n<td style=\"text-align: right; width: 85px; height: 26px;\" align=\"right\">120,273<\/td>\n<td style=\"text-align: right; width: 80px; height: 26px;\" align=\"right\">94<\/td>\n<td style=\"text-align: right; width: 112px; height: 26px;\" align=\"right\">174<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"width: 202px; text-align: left; height: 26px;\" align=\"right\"><code>System.Text.Json<\/code>\u00a0&#8211; 500 B<\/td>\n<td style=\"text-align: right; width: 85px; height: 26px;\" align=\"right\">145,631<\/td>\n<td style=\"text-align: right; width: 80px; height: 26px;\" align=\"right\">94<\/td>\n<td style=\"text-align: right; width: 112px; height: 26px;\" align=\"right\">173<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"width: 202px; text-align: left; height: 26px;\" align=\"right\"><code>Newtonsoft.Json<\/code>\u00a0&#8211; 8 KB<\/td>\n<td style=\"text-align: right; width: 85px; height: 26px;\" align=\"right\">35,408<\/td>\n<td style=\"text-align: right; width: 80px; height: 26px;\" align=\"right\">98<\/td>\n<td style=\"text-align: right; width: 112px; height: 26px;\" align=\"right\">187<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"width: 202px; text-align: left; height: 26px;\" align=\"right\"><code>System.Text.Json<\/code>\u00a0&#8211; 8 KB<\/td>\n<td style=\"text-align: right; width: 85px; height: 26px;\" align=\"right\">56,424<\/td>\n<td style=\"text-align: right; width: 80px; height: 26px;\" align=\"right\">97<\/td>\n<td style=\"text-align: right; width: 112px; height: 26px;\" align=\"right\">184<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"width: 202px; text-align: left; height: 26px;\" align=\"right\"><code>Newtonsoft.Json<\/code>\u00a0&#8211; 40 KB<\/td>\n<td style=\"text-align: right; width: 85px; height: 26px;\" align=\"right\">8,416<\/td>\n<td style=\"text-align: right; width: 80px; height: 26px;\" align=\"right\">99<\/td>\n<td style=\"text-align: right; width: 112px; height: 26px;\" align=\"right\">202<\/td>\n<\/tr>\n<tr style=\"height: 26px;\">\n<td style=\"width: 202px; text-align: left; height: 26px;\" align=\"right\"><code>System.Text.Json<\/code>\u00a0&#8211; 40 KB<\/td>\n<td style=\"text-align: right; width: 85px; height: 26px;\" align=\"right\">14,848<\/td>\n<td style=\"text-align: right; width: 80px; height: 26px;\" align=\"right\">98<\/td>\n<td style=\"text-align: right; width: 112px; height: 26px;\" align=\"right\">197<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>For the most common payload sizes,\u00a0<code>System.Text.Json<\/code>\u00a0offers about 20% throughput increase in MVC during input and output formatting with a smaller memory footprint.<\/p>\n<h2><a id=\"user-content-summary\" class=\"anchor\" href=\"https:\/\/github.com\/microsoft\/dotnet-blog\/blob\/master\/2019\/06-Jun\/json\/2019-06-json.md#summary\" aria-hidden=\"true\"><\/a>Summary<\/h2>\n<p>In .NET Core 3.0, we&#8217;ll ship the new\u00a0<code>System.Text.Json<\/code>\u00a0APIs, which provide built-in support for JSON, including reader\/writer, read-only DOM, and serializer\/deserializer. The primary goal was performance and we see typical speedups of up to 2x over Json.NET, but it depends on your scenario and your payload, so make sure you measure what&#8217;s important to you.<\/p>\n<p>ASP.NET Core 3.0 includes support for\u00a0<code>System.Text.Json<\/code>, which is enabled by default.<\/p>\n<p>Give\u00a0<code>System.Text.Json<\/code>\u00a0a try and\u00a0<a href=\"https:\/\/github.com\/dotnet\/corefx\/issues\/new\">send us feedback<\/a>!<\/p>\n<p><code>{\"happy\": \"coding!\"}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For .NET Core 3.0, we&#8217;re shipping a brand new namespace called\u00a0System.Text.Json\u00a0with support for a reader\/writer, a document object model (DOM), and a serializer. In this blog post, I&#8217;m telling you why we built it, how it works, and how you can try it. We also have a video: Getting the new JSON library If you&#8217;re [&hellip;]<\/p>\n","protected":false},"author":335,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685],"tags":[4,9,43,108,117],"class_list":["post-23568","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","tag-net","tag-net-core","tag-bcl","tag-performance","tag-releases"],"acf":[],"blog_post_summary":"<p>For .NET Core 3.0, we&#8217;re shipping a brand new namespace called\u00a0System.Text.Json\u00a0with support for a reader\/writer, a document object model (DOM), and a serializer. In this blog post, I&#8217;m telling you why we built it, how it works, and how you can try it. We also have a video: Getting the new JSON library If you&#8217;re [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/23568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/335"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=23568"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/23568\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=23568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=23568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=23568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}