https://github.com/swaggest/json-diff
Quick guide on usage
mkdir phpDiffDemo
cd phpDiffDemo
composer require swaggest/json-diff
vim test.php
<?php
require "vendor/autoload.php";
use Swaggest\JsonDiff\JsonDiff;
$originalJson = '[{"name": "Alex", "height": 180},{"name": "Joe", "height": 179},{"name": "Jane", "height": 165}]';
$newJson = '[{"name": "Joe", "height": 179},{"name": "Jane", "height": 168},{"name": "Alex", "height": 180}]';
$diff = new JsonDiff(json_decode($originalJson), json_decode($newJson), JsonDiff::REARRANGE_ARRAYS);
echo print_r( $diff->getPatch()->jsonSerialize());
:wq!php test.php
No comments:
Post a Comment