"application/json" constant in .NET framework

Maxim Eliseev picture Maxim Eliseev · Dec 18, 2013 · Viewed 36.2k times · Source

I've just declared a constant for the "application/json" content type in one of my classes.

public const string JsonContentType = "application/json";

I'm not sure it is a good practice.

Does .NET framework have a predefined const for "application/json"?

Answer

Bob Van de Vijver picture Bob Van de Vijver · Feb 12, 2019

In order to add an up-to-date answer: since dotnet core 2.1 MediaTypeNames.Application.Json has been defined.

See https://github.com/dotnet/corefx/pull/26701 for the changeset.