dev-master
9999999-dev
MIT
The Requires
- php >=5.6
The Development Requires
1.0.1
1.0.1.0
MIT
The Requires
- php >=5.6
The Development Requires
1.0
1.0.0.0
MIT
The Requires
- php >=5.6
The Development Requires
Wallogit.com
2017 © Pedro Peláez
Get a readable diff from two bits of JSON., (*1)
composer require konsulting/json-diff, (*2)
There are a few ways to use the class. It depends on your preference, see the example below. It is also possible to exclude a set of keys from the diff, also shown below., (*3)
<?php
use Konsulting\JsonDiff;
// Using 'new'
$diff = (new JsonDiff('["json"]'))->exclude(['key'])->compareTo('["different_json"]');
// Using a simple factory method
$diff = JsonDiff::original('["json"]')->exclude(['key'])->compareTo('["different_json"]');
// Using a simple 'all-in-one' static method.
$diff = JsonDiff::compare($original = '["json"]', $new = '["different_json"]', $exclude = ['key']);
The output is a JsonDiffResult that stores the following information:, (*4)
changed - a boolean signifying if there was a relevant change, (*5)
The JsonDiffResult allows access of the result in several ways:, (*6)
<?php
$diff->toArray();
[
'original' => ['...'],
'new' => ['...'],
'diff' => [
'added' => ['...'],
'removed' => ['...']
],
'changed' => true // or false if nothing changed
];
$diff->toJson(); // Json representation of toArray()
// All the properties can be accessed using array or object notation;
// original, new, added, removed, diff, changed.
$diff->diff;
$diff['diff'];
Contributions are welcome and will be fully credited. We will accept contributions by Pull Request., (*7)
Please:, (*8)
We use PHPUnit, (*9)
Run tests using PHPUnit: vendor/bin/phpunit, (*10)
MIT
MIT
MIT