diff between jsons
by Konstantin Cryman
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/deep-diff/1.0.2/deep-diff.min.js"></script>
json1: <input type="file" id="input_json1" accept="application/json">
<br/>
json2: <input type="file" id="input_json2" accept="application/json">
<br/>
<button id="button_compare"> compare </button>
JavaScript
let JSON_1 = null;
let JSON_2 = null;
const input1 = document.getElementById( 'input_json1' );
const input2 = document.getElementById( 'input_json2' );
const bttn = document.getElementById( 'button_compare' );
const fr = new FileReader();
input1.addEventListener( 'change', () => {
const file = input1.files[ 0 ];
if( file ){
fr.onload = () => {
JSON_1 = JSON.parse( fr.result );
}
fr.readAsText( file );
} else {
JSON_1 = null;
}
} );
input2.addEventListener( 'change', () => {
const file = input2.files[ 0 ];
if( file ){
fr.onload = () => {
JSON_2 = JSON.parse( fr.result );
}
fr.readAsText( file );
} else {
JSON_2 = null;
}
} );
bttn.addEventListener( 'click', () => {
if( JSON_1 && JSON_2 ){
const __diff = DeepDiff.diff( JSON_1, JSON_2 );
console.log( { __diff } );
}
} );