Implementation of JSON Merge Patch (

v1.0.2 2016-08-12 09:09 UTC

This package is auto-updated.

Last update: 2020-05-18 08:21:59 UTC


Build Status Version PHP Version

This is an(other) implementation of JSON Merge Patch written in PHP. For a PHP 5.3 compatible version please use the implementation by @clue.

Installation via Composer

$ composer require stolt/json-merge-patch


Now you can use JSON Merge Patch for PHP via the available Composer autoload file.

Apply a patch

<?php require_once 'vendor/autoload.php';

use Rs\Json\Merge\Patch;

$targetDocument = json_decode('{"title":"Goodbye!","author":{"givenName":"John","familyName":"Doe"},"tags":["example","sample"],"content":"This will be unchanged"}');

$patchDocument = json_decode('{"title":"Hello!","phoneNumber":"+01-123-456-7890","author":{"familyName":null},"tags":["example"]}');

$patchedDocument = (new Patch())->apply(
); // '{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}'

Generate a patch document

<?php require_once 'vendor/autoload.php';

use Rs\Json\Merge\Patch;

$sourceDocument = json_decode('{"a":"b","b":"c"}');
$targetDocument = json_decode('{"b":"c"}');

$generatedPatchDocument = (new Patch())->generate(
); // '{"a":null}'

Merge patch documents

<?php require_once 'vendor/autoload.php';

use Rs\Json\Merge\Patch;

$patchDocument1 = json_decode('{"a":"b"}');
$patchDocument2 = json_decode('{"b":"c"}');

$mergedPatchDocument = (new Patch())->merge(
); // '{"a":"b","b":"c"}'

Running tests

$ composer test


This library is licensed under the MIT license. Please see LICENSE for more details.


Please see CHANGELOG for more details.


Please see CONTRIBUTING for more details.