<?php
//example run:
//a) open CMD (administartor)
//b) nvaigate to the split_jsons.php file pathinfo
//c) 
//c:\xampp\php\php.exe split_jsons.php <<path to input big json file>>

$file = $argv[1]; //fetch the file_path from command line

//create output folder where the file located
if (!is_dir(".".DIRECTORY_SEPARATOR.'output')){
    mkdir(".".DIRECTORY_SEPARATOR.'output', 0777);
}

$content = file_get_contents($file); //read the data from the file

$content=iconv("UTF-16", "UTF-8", $content); //convert non-utf8 content to utf8

$jsons = json_decode($content,true); //fetch the jsons array - each element different file
  
//iterate over the array and create new json files
$i = 0;
foreach($jsons as $jsonData){
    $jsonData = json_encode($jsonData, true);
    file_put_contents(".".DIRECTORY_SEPARATOR.'output'.DIRECTORY_SEPARATOR."json_".$i.'.json', $jsonData);
    $i++;
}

