DEV Community

loading...
Cover image for Xamarin: Newtonsoft vs vs system.text.json

Xamarin: Newtonsoft vs vs system.text.json

jorgecc profile image Jorge Castro Originally published at southprojects.com ・2 min read

Xamarin: Newtonsoft-Json vs system.text.json in a nutshell.

Newtonsoft-Json is the de-facto library to serialize and de-serialize values using JSON and it is the library with the most downloads in NuGet.
A couple of years ago, Microsoft launched an alternative to Newtonsoft-Json called system.text.json. Microsoft promoted as a new namespace but what is a namespace?. A namespace is what we could call a "logical folder" where we put our projects. But practically every library has a namespace.

But, back to the topic. Which is better?

  • System.text.json comes included with the net core version. Well.. no really. If you target standard (Xamarin) or framework, then you must install it via NuGet, Newtonsoft-JSON too.

  • System.text.json is backed by Microsoft. However, it means nothing. I will explain it later. While Newtonsoft-JSON has a long record of support and usability, it is a well-proven library.

  • System.text.json is better than Newtonsoft-JSON. Well.. no.

https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to?pivots=dotnet-5-0

There are several features that support Newtonsoft-JSON and they are not supported by System.text.json. Microsoft is backing it but system.text.json is a 2-year-old library and it still misses lots of features

  • Benchmark.

System.text.json is around 200% fastest than Newtonsoft-JSON. Why? It is because system.text.json does not need to convert UTF-8 back and forth also other performances (system.text.json is case sensitive).

Conclusion:

If you want speed, then system.text.json is your thing. Otherwise, stick with Newtonsoft-JSON because it has more features and it is more compatible with different solutions.

Discussion (0)

pic
Editor guide