34

What is better to use when it comes to encoding and decoding of JSON in .NET? I have tried both and upto this point JsonConvert seems to be doing a good job. I have used JavaScriptSerializer in the past successfully but have had some problems in the recent past with it. Is it better to use JSON.NET than the .NET class?

What are the preferred functions for encoding/decoding json using the appropriate library? I use SerializeObject/DeSerializeObject from JSON.NET and Serialize/DeSerialize from .NET.

Thanks

2
  • 1
    There is good comparison here in terms of speed. Even after reading this article I've used Newtonsoft.Json, as it did decent job for me. Commented Jun 29, 2012 at 14:03
  • The Newtonsoft website provides a table of feature comparison and some benchmarks worth having a look at too: newtonsoft.com/json/help/html/JsonNetVsDotNetSerializers.htm Commented Feb 12, 2019 at 8:30

2 Answers 2

45

I think this is exactly the kind of comparison you are looking for.

It basically says that JSON.Net is better because it among other things...

  • Is faster
  • Has LINQ to JSON support
  • Can convert JSON to and from XML

In my opinion the only positive, (and it is a small positive), I can see for the built-in serializer is that there is no extra external dependency to manage.

Edit: Codeplex is shutting down one day so you can find the comparison here as well, just search for "Feature comparison" on the page.

Sign up to request clarification or add additional context in comments.

3 Comments

Is faster Did you test it? I tried with .NET 4.5.2 and Json.NET 9.01 and it's not at all faster than the JavaScriptSerializer. The speed stats in the official site are referring to JSON.NET 5...a little outdated!
@krlzlx .Net 4.5.2 was released in May 2015, and JSON.Net 9.01 a few months ago while I wrote this answer 3 years ago in 2013. Why don't you provide an updated answer with your metrics instead of being snarky!
I'm sorry I know your answer is from 2013. But you didn't provide any metrics either except from the ones in the Json.NET website. I was disappointed when I tested it. That's all.
28

For a very long time, my app used JavascriptSerializer and saw no real reason to migrate. Even if performance comparisons claim huge percentage gains, we're talking milliseconds.

But here's one very very good reason to migrate: JavascriptSerializer isn't available in .Net Core because it's part of System.Web So if you're using JavascriptSerializer, you're stuck and have to migrate to JSON.net

2 Comments

asp net core uses json.net by default.
.Net core now has the System.Text.Json serialisers so this is no longer correct. MS now want you to use this serialiser not the Newtonsoft one. Though to echo your point (above) I haven't seen a need to move TBH

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.