Skip to main content
Skip table of contents

Patch Guide

JSON Patch is useful when you want to apply updates to files in remote locations.  For example, I have file 'A' and have updated it to file 'B'.  I can send the patch file to other locations who are using (but have not modified) file 'A' so they can update it to file 'B'. If other locations have updated their file 'A' as well then Graft will be more useful.

In this example the patch file is larger than the data file. In a typical case the data file could be very large with just a few modifications meaning that the patch file will be much smaller than the data file. 

The two inputs are specified along with the patchDirection which can be aToB or bToA. The default is aToB. Also dxConfig can be used,  this is initially setup to allow ignoring changes for certain keys. See Ignore Changes.

Input A
TEXT
{"a":"your data","b":"bbc 1","name":"John Joe Smith","age":21,"owner":true,"hobbies":["playing guitar badly","reading","Cinema"]}
Input B
TEXT
{"a":"my data","b":"bbc 2","name":"Mr John Smith","hobbies":["Badminton","guitar","reading"],"age":22,"pet":"dog"}
Result File with default settings
TEXT
[
    {
        "op": "replace",
        "path": "/a",
        "value": "my data"
    },
    {
        "op": "replace",
        "path": "/b",
        "value": "bbc 2"
    },
    {
        "op": "replace",
        "path": "/name",
        "value": "Mr John Smith"
    },
    {
        "op": "replace",
        "path": "/age",
        "value": 22
    },
    {
        "op": "remove",
        "path": "/hobbies/2"
    },
    {
        "op": "add",
        "path": "/hobbies/1",
        "value": "guitar"
    },
    {
        "op": "replace",
        "path": "/hobbies/0",
        "value": "Badminton"
    },
    {
        "op": "remove",
        "path": "/owner"
    },
    {
        "op": "add",
        "path": "/pet",
        "value": "dog"
    }
]

For details of requests see Patch Request.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.