How to merge two JSON files in PHP?

If you need merge information from two json files with same structure but with different values then you can use this overide recursive method

//Recursive method for merge 2 json files
function mergeJsonArrays($priority_json, $original_json_content)
        foreach ($original_json_content as $org_content_key => $org_content_value) {
            if (!array_key_exists($org_content_key, $priority_json)) {
                $priority_json[$org_content_key] = $org_content_value;
            } elseif (!is_string($org_content_value)) {
                $priority_json[$org_content_key] =  mergeJsonArrays($priority_json[$org_content_key], $org_content_value);
        return $priority_json;

 $jsonAssoc = true;
  $first_config_file_path = 'config_folder/first_json_file.json';
  $json_first = is_file($first_config_file_path) ? json_decode(file_get_contents($first_config_file_path), $jsonAssoc) : NULL;

  $second_config_file_path = 'config_folder/second_json_file.json';
  $json_second = is_file($second_config_file_path) ? json_decode(file_get_contents($second_config_file_path), $jsonAssoc) : NULL;

 $result_json = mergeJsonArrays($json_first, $json_second);

Example [config_folder/first_json_file.json]
Continue reading How to merge two JSON files in PHP?