php-jsonpatch
php-jsonpatch copied to clipboard
Feature request: Generate JSON patch from two json string
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"]}}
...
...
]';
*/
Not quite sure when I'll find the time to implement this feature. As always with OSS a qualified pull request is welcome.
You might also consider using JSON Merge Patch for PHP for your use case.
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.