Skip to content

Instantly share code, notes, and snippets.

Created May 18, 2013 12:28
What would you like to do?
Merges JSON files
$source = json_decode(file_get_contents('french.json'), true);
$dest = json_decode(file_get_contents('auto_french.json'), true);
function mergeArray($source, $dest) {
foreach ($dest as $k => $v) {
if (!array_key_exists($k, $source)) {
$source[$k] = $v;
} elseif (!is_string($v)) {
$source[$k] = mergeArray($source[$k], $v);
return $source;
$new = mergeArray($source, $dest);
file_put_contents('new_french.json', json_encode($new, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment