-3

I have a json file that runs as follows

{
"1" : [...],
"2" : [...]
}

Is there any way to combine them all as one?

IamrSA
  • 3
  • 3

2 Answers2

0

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]);

}
Mitesh Pant
  • 524
  • 2
  • 15
0
<?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));

?>

Mitesh Pant
  • 524
  • 2
  • 15