Which JsonPatch Flavour Should I Use?

With the recent v1 release of Marvin.JsonPatch & Marvin.JsonPatch.Dynamic, I figured this would be a good time for a write-up of which flavour to use for which use case.

There are 3 different flavours: Marvin.JsonPatch, Marvin.JsonPatch.Dynamic, and Microsoft.AspNetCore.JsonPatch.

Marvin.JsonPatch is a PCL, targeting Xamarin, WinPhone, .NET 4.

Marvin.JsonPatch.Dynamic targets the full .NET framework.  It references Marvin.JsonPatch and adds support for dynamically typed objects (for example: with the add operation you can effectively add previously non-existent properties to the object you’re applying the patch to if it’s an ExpandoObject).

Microsoft.AspNetCore.JsonPatch is a port of both, in one assembly, targeting .NET Core (.NET Standard).

When working with JsonPatch there’s two things of importance: what happens on the client (creating the JsonPatchDocument & serializing it) and what happens on the server (deserializing the JSON into a JsonPatchDocument & applying it).  Depending on the app you’re building, you’ll use one or the other, or both.

My recommendation is: use the flavour that best fits the target framework you’re working with.  If you’re building a Xamarin app that talks to an API built with ASP.NET Web API, use Marvin.JsonPatch on the client and Marvin.JsonPatch.Dynamic on the server.  If your client application is an ASP.NET MVC application and your API is built with ASP.NET Core, use Marvin.JsonPatch.Dynamic on the client and Microsoft.AspNetCore.JsonPatch on the server, and so on.

Due to the fact that the three flavours implement the same standard, they work together seamlessly.

Happy coding! :-)

 Tweet about this on TwitterShare on LinkedInShare on Facebook



Can we use Marvin.JsonPatch.Dynamic in a pure .NET Class library ( no server side at all) to transform a JSON document into another JSON doc? Have seen multiple implementations but all in node.js environment or if using JSON Patch then having an API implementation also. We are basically in need of a JSON Mapper and transformer ( something like JOLT in Java but not necessarily as complex or so many features).
Can this work for us ( even if with some modifications).


Leave a Reply

Your email address will not be published. Required fields are marked *