5

The MSDN documentation of the JavaScriptSerializer-class states:

Json.NET should be used serialization and deserialization. Provides serialization and deserialization functionality for AJAX-enabled applications.

Should this be some sort of deprecation hint or should this class not be used in general at all (for the purpose of JSON serialization)?

Liam
  • 27,717
  • 28
  • 128
  • 190
0xDECAFBAD
  • 627
  • 1
  • 8
  • 21
  • Possible duplicate of [JSON.NET JsonConvert vs .NET JavaScriptSerializer](http://stackoverflow.com/questions/11263166/json-net-jsonconvert-vs-net-javascriptserializer) – GSerg Oct 28 '16 at 09:49

1 Answers1

7

2021

In 2021 the JavaScriptSerializer is not only deprecated it has been removed in .Net Core and .Net 5.x. So you can't use this anymore unless your targeting the .Net Framework 4.8 or below.

The replacement is the System.Text.Json suite of classes.


Is it deprecated

No. Otherwise, they would have marked it obsolete.

should this class not be used in general

Providing your targetting .Net Framework 4.8 or below then sure you can use it, if you want to taregt .Net core or .Net 5 then you can't as it's not available anymore.


This is here as a comparision between the available .Net Framework classes. I actually go into more detail on System.Text.Json vs Json.Net in another answer.

Now is it the best serialiser to use? Basically no and even Microsoft know this and use Json.Net internally for things such as the Web.API. Hence the recommendation. It has several advantages over the JavaScriptSerializer. It seems the new Microsoft is attempting to embrace the open source community (hopefully not to extinguish it...) and utilise the wealth of tools out there.

It seems Microsoft can't make up their minds about making it actually obsolete. My guess is they still maintain it because it's used internally and re-writing stuff to use Json.Net is just more work than it's worth.

Tl;Dr

Use Json.Net if your targetting .Net Framework 4.8 or below, for .Net core or .Net 5 then you can choose between Json.Net or System.Text.Json.

Liam
  • 27,717
  • 28
  • 128
  • 190