Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Newtonsoft: Json.NET in ASP.NET Core WebAPI? [duplicate]

I found some information about nuget package - Newtonsoft: Json.NET

As far I know it makes serialization from JSON to C# object much faster.

My question: Is it enough to install this package to my ASP.NET CORE WebAPI project or I have bind it somehow, dunno maybe with middleware or something? And it will makes serialization faster?

like image 575
DiPix Avatar asked May 10 '17 19:05

DiPix


People also ask

Is Newtonsoft JSON compatible with .NET core?

ASP.NET Core MVC features that use Newtonsoft. Json. Includes input and output formatters for JSON and JSON PATCH. Learn more about Target Frameworks and .

Is JSON NET the same as Newtonsoft JSON?

Thanks. Json.NET vs Newtonsoft. Json are the same thing. You must be trying to use the same code with different versions of Json.NET.

Which is better Newtonsoft JSON or system text JSON?

Text. Json is much faster than the Newtonsoft. Json.

Why we use Newtonsoft JSON DLL?

The Newtonsoft. JSON namespace provides classes that are used to implement the core services of the framework. It provides methods for converting between . NET types and JSON types.


1 Answers

You don't need to do anything special to get Newtonsoft.JSON to work. Simply install it through NuGet (or manually) and you're good to go. You will however have to go through your code and replace any code you wrote to work with JSON before installing it.

EDIT: You dont even have to do that! Turns out .Net Core uses it out of the box. Refer to this answer for how to use it natively.

UPDATE: From the answer linked above:

This is only true for ASP.NET Core 1.0 to 2.2. ASP.NET Core 3.0 removes the dependency on JSON.NET and uses it's own JSON serializer.

As for performance, there are a few benchmarks out there that compare alternative ways of serializing and deserializing JSON. A quick google search led me to this, as well as this.

like image 73
stelioslogothetis Avatar answered Sep 26 '22 22:09

stelioslogothetis