I have a json file that runs as follows
{
"1" : [...],
"2" : [...]
}
Is there any way to combine them all as one?
I have a json file that runs as follows
{
"1" : [...],
"2" : [...]
}
Is there any way to combine them all as one?
You will have to write a javascript code for this.
var primarJson = {
"1" : [1, 2,3,4],
"2" : [5, 6,7,8],
"3" : [9, 10,11,12],
"4" : [13, 14,15,16]
}
var combinedJson = { "final" : []}
for(var i in primarJson){
combinedJson.final = combinedJson.final.concat(primarJson[i]);
}
<?php
$primarJson = '{
"1" : [1, 2,3,4],
"2" : [5, 6,7,8],
"3" : [9, 10,11,12],
"4" : [13, 14,15,16]
}';
$finalArray = json_decode('{"final" : []}', true);
foreach (json_decode($primarJson) as $key => $value) {
$finalArray['final'] = array_merge($value, $finalArray['final']);
}
print_r(json_encode($finalArray));
?>