I wish to compare 2 json files( a.json , b.json) in php .
Files a.json and b.json will have array of json in it .
Files a.json and b.json will have different alignment but the json array data will remains same
Is there any libraries for the above.
can any on help me out on this ?
You can decode json array to a normal array using the PHP function json_decode() for both the files and then you can use array_diff_key(). This last function return the difference by key of the two arrays, if the result is empty then your files are equal.
$arrayA = json_decode(file_get_contents('path/to/a.json'),true);
$arrayB = json_decode(file_get_contents('path/to/b.json'),true);
$result = array_diff_key($arrayA,$arrayB);
if(empty($result)){
//Same file
}else{
//Differences occured
}
Let me know if it made the trick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With