{"id":25510205,"url":"https://github.com/ruyut/jsonpatchsupport.aspnetcore","last_synced_at":"2026-04-30T14:31:29.029Z","repository":{"id":278336284,"uuid":"934797620","full_name":"ruyut/JsonPatchSupport.AspNetCore","owner":"ruyut","description":"Lightweight ASP.NET Core package integrating JSON Patch support via Newtonsoft.Json for efficient partial updates.","archived":false,"fork":false,"pushed_at":"2025-02-19T07:50:34.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-19T08:31:18.757Z","etag":null,"topics":["api","asp-net-core","csharp","csharp-library","json"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruyut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-18T12:23:58.000Z","updated_at":"2025-02-19T07:50:37.000Z","dependencies_parsed_at":"2025-02-19T08:42:16.487Z","dependency_job_id":null,"html_url":"https://github.com/ruyut/JsonPatchSupport.AspNetCore","commit_stats":null,"previous_names":["ruyut/jsonpatchsupport.aspnetcore"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruyut%2FJsonPatchSupport.AspNetCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruyut%2FJsonPatchSupport.AspNetCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruyut%2FJsonPatchSupport.AspNetCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruyut%2FJsonPatchSupport.AspNetCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruyut","download_url":"https://codeload.github.com/ruyut/JsonPatchSupport.AspNetCore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239630222,"owners_count":19671439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","asp-net-core","csharp","csharp-library","json"],"created_at":"2025-02-19T09:28:40.276Z","updated_at":"2025-11-24T03:30:14.373Z","avatar_url":"https://github.com/ruyut.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonPatchSupport.AspNetCore\n\n[![NuGet version (JsonPatchSupport.AspNetCore)](https://img.shields.io/nuget/v/JsonPatchSupport.AspNetCore)](https://www.nuget.org/packages/JsonPatchSupport.AspNetCore)\n[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ruyut/JsonPatchSupport.AspNetCore/publish.yml)](https://github.com/ruyut/JsonPatchSupport.AspNetCore/actions/workflows/publish.yml)\n\n## Overview\n\nJsonPatchSupport.AspNetCore is a lightweight package that enables JSON Patch support in ASP.NET Core using the\nNewtonsoft.Json library, allowing simple partial updates with minimal configuration.\n\nFor more details, visit the related blog post:\n[ASP.NET Core JSON Patch API Example](https://www.ruyut.com/2025/02/aspnet-core-json-patch-api.html)\n(written in Traditional Chinese).\n\n## Installation\n\nInstall the package via .NET CLI:\n\n```bash\ndotnet add package JsonPatchSupport.AspNetCore\n```\n\nAlternatively, add a project reference to your ASP.NET Core application.\n\n## Usage\n\n**Register Services**\n\nAdd the auto service registration extension in your service configuration:\n\n```csharp\n// add using directive\nusing JsonPatchSupport.AspNetCore;\n\nvar builder = WebApplication.CreateBuilder(args);\n\n// register service\nbuilder.Services.AddJsonPatchSupport();\n\nvar app = builder.Build();\n```\n\n## API Example\n\nBelow is an example of how to use JSON Patch in an API controller:\n\n```csharp\nusing Microsoft.AspNetCore.JsonPatch;\nusing Microsoft.AspNetCore.Mvc;\n\n\n[ApiController]\n[Route(\"api/[controller]\")]\npublic class ProductController : ControllerBase\n{\n    [HttpPatch(\"{id}\")]\n    public IActionResult Patch([FromRoute] int id, [FromBody] JsonPatchDocument\u003cProductDto\u003e patchDocument)\n    {\n        // Simulate getting the entity from a data source\n        var product = new ProductDto\n        {\n            Name = \"product1\",\n            Price = 10,\n        };\n\n        // Apply the patch to the product\n        patchDocument.ApplyTo(product, ModelState);\n\n        if (!ModelState.IsValid)\n        {\n            return BadRequest(ModelState);\n        }\n\n        // Simulate saving the updated entity to a data source\n\n        return Ok(product);\n    }\n}\n\npublic class ProductDto\n{\n    public string Name { get; set; }\n    public int Price { get; set; }\n}\n```\n\nExample JSON Patch document:\n\n```json\n[\n  {\n    \"op\": \"replace\",\n    \"path\": \"/Name\",\n    \"value\": \"NewProductName\"\n  },\n  {\n    \"op\": \"replace\",\n    \"path\": \"/Price\",\n    \"value\": \"99\"\n  }\n]\n```\n\nExample cURL request:\n\n```shell\ncurl -X 'PATCH' \\\n  'http://localhost:5183/api/Product/1' \\\n  -H 'accept: */*' \\\n  -H 'Content-Type: application/json-patch+json' \\\n  -d '\n[\n  {\n    \"op\": \"replace\",\n    \"path\": \"/Name\",\n    \"value\": \"NewProductName\"\n  },\n  {\n    \"op\": \"replace\",\n    \"path\": \"/Price\",\n    \"value\": \"99\"\n  }\n]'\n```\n\nExpected response:\n\n```text\n{\n  \"name\": \"NewProductName\",\n  \"price\": 99\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruyut%2Fjsonpatchsupport.aspnetcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruyut%2Fjsonpatchsupport.aspnetcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruyut%2Fjsonpatchsupport.aspnetcore/lists"}