php-jsonpatch icon indicating copy to clipboard operation
php-jsonpatch copied to clipboard

Feature request: Generate JSON patch from two json string

Open cpxPratik opened this issue 7 years ago • 3 comments

Is it possible to add feature to generate json string(which contains JSON patch) for two json strings like in below given code, I needed this feature along with applying patch which is already there.

$initial_document =  '{"a":{"b":["c","d","e"]}}';
$updated_document = '{"a":{"b":["c","d","e"],"c":["a","b"],"e":["a"]}}';
$patch_diff = new JsonPatch($initial_document, $updated_document); //
$document_diff = $patch_diff->get_patch();
/* 
$document_diff = '[
        {"op":"add", "path":"/a/d", "value":["a","b"]}, // {"a":{"b":["c","d","e"],"d":["a","b"]}}
        ...
        ...
    ]';
*/

cpxPratik avatar Apr 20 '17 06:04 cpxPratik

Not quite sure when I'll find the time to implement this feature. As always with OSS a qualified pull request is welcome.

raphaelstolt avatar Apr 20 '17 10:04 raphaelstolt

You might also consider using JSON Merge Patch for PHP for your use case.

raphaelstolt avatar Apr 20 '17 17:04 raphaelstolt

I just wanted to +1 this... I know a pull request would be more desirable :). I may have to implement this as the other main package - https://github.com/mikemccabe/json-patch-php is insanely slow when generating patches.

P.S. Thanks for your awesome work on this package, the code is so clean and well layed out.

joeynovak avatar Nov 30 '21 01:11 joeynovak