I split a large Json file to more correctly edit the information. Now that I edit it, how can I merge them back in php? -


i had master json split individual files more accurately/correctly edit information. did edits , combine them 1 master json in php. current way have set globing jsons, doing foreach , concatenating seem having trouble concatenation. tried array_merge_recursive , @ first ended 1 small json values set null , second time got 1 set of keys, each value being whole json repeated on , on again. help!

edit: have 1 master json looks -

"hello": {     "title": "hello",     "elang": "english",     "abbr": "hllo", }, "world": {     "title": "world",     "elang": "english",     "abbr": "wlrd", }, 

i made each json it's own file accordingly doing -

$part2 = json_decode(file_get_contents('../json/master2.json'), true);     foreach ($part2 $keyp3 => $valuep3) {         file_put_contents("../json/individual/$keyp3.json", json_encode($valuep3, json_pretty_print | json_unescaped_unicode | json_unescaped_slashes));     } 

after separated them, ran glob , edited specific lines info placed want. below code advised use isn't outputing data correctly, nor of data have:

$final = []; foreach ($indjson $keyp5 => $valuep5) {     $indv = json_decode(file_get_contents("$valuep5"), true);     foreach ($indv $key52 => $value52) {         $final[$key52] = array_merge_recursive(json_decode(file_get_contents("$valuep5"), true), $final);     } file_put_contents('../json/finished.json', json_encode($final, json_pretty_print | json_unescaped_unicode | json_unescaped_slashes)); } 

assuming $indjson map key master json property name , value filename containing inner json, here's code should like;

$final = []; // each file foreach ($indjson $keyp5 => $valuep5) {     // content of each file array     $indv = json_decode(file_get_contents("$valuep5"), true);     // add inner array final array     $final[$keyp5] = $indv; } // after finish iterating, can write out master file file_put_contents('../json/finished.json', json_encode($final,          json_pretty_print | json_unescaped_unicode | json_unescaped_slashes)); 

suggestions future

  • use more meaningful variables names, $keyp5 kind of cryptic, specially on tried @ code , make sense of it.
  • do debugging on own, print out output of $final each time through iteration

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -