Ali Yiğit Ali Yiğit -5 years ago 169
JSON Question

combine many json files into one

I am trying to combine all json files into one.However i always receive an empty json file . Here is code ;

function mergejson()
$events = array();
// open each jsonfile in this directory
foreach(glob("*.json") as $filename) {
// get the contents of the the current file
$data[] =json_decode($filename, true);
$events= array_merge($events,$data);
$file_name ='merge.json';
$events =json_encode($events,true);

Answer Source

The function json_decode takes a string as first argument, not a filename!

So you have to load the file content, try using file_get_contents

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download