Friday, 26 March 2021

Exploring JSON merge patch

JSON merge patch defines the JSON merge patch format and processing rules.  The merge patch format is primarily intended for use with the HTTP PATCH method as a means of describing a set of modifications to a target resource's content.

 

Algorithm to apply a patch json on target json looks like below.

     define MergePatch(Target, Patch):
       if Patch is an Object:
         if Target is not an Object:
       Target = {} # Ignore the contents and set it to an empty Object
         for each Name/Value pair in Patch:
       if Value is null:
         if Name exists in Target:
           remove the Name/Value pair from Target
       else:
         Target[Name] = MergePatch(Target[Name], Value)
         return Target
       else:
         return Patch

 

Reference

https://tools.ietf.org/html/rfc7386

 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment