PartialResponse.AspNetCore.Mvc.Formatters.Json
PartialResponse.AspNetCore.Mvc.Formatters.Json provides JSON partial response (partial resource) support for ASP.NET Core MVC.
Install / Use
/learn @dotarj/PartialResponse.AspNetCore.Mvc.Formatters.JsonREADME
ASP.NET Core MVC Partial Response
PartialResponse.AspNetCore.Mvc.Formatters.Json provides JSON partial response (partial resource) support for ASP.NET Core MVC. This package is also available for ASP.NET Web API.
Getting started
First, add a dependency to PartialResponse.AspNetCore.Mvc.Formatters.Json using the NuGet package manager (console) or by adding a package reference to the .csproj:
<ItemGroup>
<PackageReference Include="PartialResponse.AspNetCore.Mvc.Formatters.Json" Version="x.x.x" />
</ItemGroup>
Then, remove the JsonOutputFormatter from the output formatters and add the PartialJsonOutputFormatter:
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc(options => options.OutputFormatters.RemoveType<JsonOutputFormatter>())
.AddPartialJsonFormatters();
}
The fields parameter value, which is used to filter the API response, is case-sensitive by default, but this can be changed using the MvcPartialJsonOptions:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<MvcPartialJsonOptions>(options => options.IgnoreCase = true);
}
That's it!
Understanding the fields parameter
The fields parameter filters the API response so that the response only includes a specific set of fields. The fields parameter lets you remove nested properties from an API response and thereby reduce your bandwidth usage.
The following rules explain the supported syntax for the fields parameter value, which is loosely based on XPath syntax:
- Use a comma-separated list (
fields=a,b) to select multiple fields. - Use an asterisk (
fields=*) as a wildcard to identify all fields. - Use parentheses (
fields=a(b,c)) to specify a group of nested properties that will be included in the API response. - Use a forward slash (
fields=a/b) to identify a nested property.
In practice, these rules often allow several different fields parameter values to retrieve the same API response. For example, if you want to retrieve the playlist item ID, title, and position for every item in a playlist, you could use any of the following values:
fields=items/id,playlistItems/snippet/title,playlistItems/snippet/positionfields=items(id,snippet/title,snippet/position)fields=items(id,snippet(title,position))
Note: As with all query parameter values, the fields parameter value must be URL encoded. For better readability, the examples in this document omit the encoding.
Note: Due to the relatively slow performance of LINQ to JSON (Json.NET), the usage of PartialJsonOutputFormatter has a performance impact compared to the regular Json.NET serializer. Because of the reduced traffic, the overhead in time could be neglected.
Related Skills
openhue
341.6kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
341.6kElevenLabs text-to-speech with mac-style say UX.
weather
341.6kGet current weather and forecasts via wttr.in or Open-Meteo
tweakcc
1.5kCustomize Claude Code's system prompts, create custom toolsets, input pattern highlighters, themes/thinking verbs/spinners, customize input box & user message styling, support AGENTS.md, unlock private/unreleased features, and much more. Supports both native/npm installs on all platforms.
Languages
Security Score
Audited on Jun 3, 2022
