Skip to content
Go to file


Failed to load latest commit information.
Latest commit message
Commit time
Jul 21, 2014
Jul 21, 2014


JsonPatch is a simple library which adds JSON Patch support to ASP.NET Web API (

You can get it on NuGet here:


Step 1: Install the formatter

public static void ConfigureApis(HttpConfiguration config)
    config.Formatters.Add(new JsonPatchFormatter());

Step 2: Profit??

public void Patch(Guid id, JsonPatchDocument<SomeDto> patchData)
    //Remember to do some validation and all that fun stuff
    var objectToUpdate = repository.GetById(id);

Making a PATCH request

The main thing is to make sure the content type is "application/json-patch+json" otherwise Web API won't invoke the JsonPatch media formatter. Here's an example.

PATCH /my/data HTTP/1.1
Content-Type: application/json-patch+json

    { "op": "add", "path": "/a/b/c", "value": "foo" }


The path specified in the patch request can be resolved to a different property on the model using a resolver.

E.g. the FlexiblePathResolver will match a property based on

  • The JsonProperty attribute
  • The DataMember attribute
  • The Property Name (Case Insensitive)
config.Formatters.Add(new JsonPatchFormatter(new JsonPatchSettings
     PathResolver = new FlexiblePathResolver()

Now the request

PATCH /my/data HTTP/1.1
Content-Type: application/json-patch+json

    { "op": "add", "path": "/sampleProperty", "value": "foo" }

Will be valid for the class

    public string SampeProperty {get;set;}

Available resolvers are

  • ExactCasePropertyPathResolver (default for backwards compatibility)
  • CaseInsensitivePropertyPathResolver
  • AttributePropertyPathResolver
  • FlexiblePathResolver


Because we are applying updates to C# objects rather than JSON objects we differ from the spec slightly, here are some points of difference.

JSON Pointer (rfc6901)

The JSON patch document uses JSON pointers to refer to properties, we don't accept paths in the following formats:

  1. The path "" is invalid as it refers to the whole object, if you're replacing everything, just use PUT.
  2. The path "/" is invalid as you cannot have an empty property.
  3. The path "/5" is invalid as you can only update an entity, not an array of entities.

Available operations (rfc6902#section-4)

We only support a subset of available operations at this moment, add, remove, and replace.

Since C# is a typed language we have a few restrictions, hence the operations work a little differently than specified in the specification.

Here's our flavour:

  1. Add will not add a property that does not exist, it can only be used to specify values on properties that are null.
  2. Remove will not remove a property, it will set its value to null.
  3. Replace will replace the value of a property even if it is null.

This is still very much an early project, don't use it in production yet unless you understand the source and don't mind fixing a few bugs ;)

Twitter: @myquay


Adds JSON Patch support to ASP.NET Web API (




No releases published


You can’t perform that action at this time.