Write JSON file

function writeJSON($data, $file) {
    $fp = fopen($file, 'w');
    $result = fwrite($fp, json_encode($data));
    fclose($fp);
    if($result===false) {
        return $result;
    }
    return true;    
}