Merge Json files

With this small script you could merge some json files in a new one in json validated format.  The script uses each file name like array key.

Look the example:






Whit our script you could run:


Now you can open merged_jsons.json and look this:


The script:

for ( $i=1; $i{
$file_name = basename($argv[$i]);
$key_name = strstr($file_name,'.',true);
$data = file_get_contents( $argv[$i] );
$result[$key_name]=json_decode( $data );}echo json_encode( $result );