Finally, .NET got JSON API

By | June 17, 2019

Dealing with JSON data is a pretty standard use case in modern application development and .NET applications are no exception. When compared to XML data type which apparently has built-in support with lot of libraries and interfaces in .NET Framework. Remember, LINQ to XML which gives in-memory LINQ query interface over XML data source. Strangely, there is no LINQ to JSON. It is quite clear that .NET had lagged historically in providing similar level of treatment to JSON data type in .NET framework. Of course, There are classes like DataContractSerializer and JavaScriptSerializer which came with .NET framework offered to solve JSON processing but that support ended up being basic serialization/deserialization support to convert JSON data into/from .NET types. .NET developers sulkingly sailed along with these bloated and slow classes with out much choice in those days of WCF and Javascript AJAX development.


Just around that same time, Open source Json.NET library addressed to fill gaps for JSON processing in .NET world. It quickly became the preferred choice for .NET serialization needs. In fact, it is easy-to-use, high performing and provided multitude of features which clearly are lacking in the DataContractSerializer and JavaScriptSerializer classes. For example, to name a few, there is no indenting support,Camel casing or XPath query syntax support in above .NET JSON classes Check here for feature comparison between Json.NET and .NET JSON serializers. Json.NET is feature rich and it even has JSON Schema support which means it can validate and generate JSON schema. No wonder, It gained full support of .NET Community to the extent .NET framework started relying on Json.NET as a default JSON processor in .NET ecosystem. ASP.NET Core went a step further by making it a core assembly in ASP.NET Core

Enter the new System.Text.Json API

Microsoft announced recently they’re shipping brand new assembly System.Text.JSON with .NET Core 3 preview release. The new API offers better performance over Json.NET as evidenced in the benchmark tests. It aims to remove tighter Json.NET dependency from ASP.NET Core. For Json.NET lovers, ASP.NET Core is giving alternate Json.NET integration via AddJsonOptions extension method. New API is fully supported in ASP.NET Core and SignalR. Please note new API has further work to do. Support for Open API/Swagger is ongoing and field serialization is not supported yet.

For full in-depth details on new System.Text.Json API, please see this excellent article. There is also a channel 9 video which walks through new JSON Api