Aspnetcore.docs: What is the scope of AddNewtonsoftJson()?

Created on 17 Sep 2020  Â·  7Comments  Â·  Source: dotnet/AspNetCore.Docs

When you call AddNewtonsoftJson on a particular method:

services.AddRazorPages().AddNewtonsoftJson();

...is the scope limited to RazorPages (in this example), or does it affect the entire pipeline, equivalent (as far as JSON.NET is concerned) to calling

services.AddMvc().AddNewtonsoftJson();

I ask because some third-party libraries use JSON.NET still but my project doesn't (in this case Coravel Pro, which also uses RazorPages which my application also doesn't), and I'm concerned about potential conflicts.

Hopefully this is an appropriate place to ask this question; if not please feel free to redirect me. Thanks.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

GII Source - Docs.ms doc-bug

All 7 comments

@Tratcher 30 second question

@pranavkm

Razor Pages and MVC have the same underpinnings. If you reference a library that calls AddNewtonsoftJson on your behalf, it will also affect controllers (and other MVC features) in your app.

Within MVC, it changes the following things to use Json.Net:

  • input and output formatting (reading or writing) of JSON an ActionResult
  • JsonResult
  • IJsonHelper
  • adds support for JsonPatch
  • the serialization format used internally by ITempDataDictionary

cc @serpent5 if you're interested in updating this doc.

Thank you, that answered my question precisely. I would close this but I'll defer to @serpent5 in case he wants to clarify this in the doc. If not, feel free to close. Thanks again.

I'm happy to do something here. How about adding a "for more information" link in this migration topic to the Add Newtonsoft.Json-based JSON format support section in "Format response data in ASP.NET Core Web API" and including some of Pranav's information in that section?

@serpent5 that would be great.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AnthonyMastrean picture AnthonyMastrean  Â·  3Comments

StevenTCramer picture StevenTCramer  Â·  3Comments

davisnw picture davisnw  Â·  3Comments

Raghumu picture Raghumu  Â·  3Comments

YeyoCoder picture YeyoCoder  Â·  3Comments