Report inadequate content

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:

  • php merge_jsons.php file1.json file2.json > merged_jsons.json


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 );

Leave your comment Merge Json files

Log in to Obolog, or create your free blog if you are not registered yet.

User avatar Your name