0

I'm new to JSON and trying to join two PHP arrays and output the result as JSON. I ran the output into a JSON validator and it said it was ok but I'm not convinced. How can I replace the "0" on line 4 of the output to be "genres" and will the output be easy to pull out each genre name by the receiver?

{
"apiVersion": "1.0",
"status": "ok",
"0": [
    {
        "id": 0,
        "name": "Miscellaneous",
        "like": "NO"
    },
    {
        "id": 1,
        "name": "Breakbeat",
        "like": "NO"
    },
    {
        "id": 2,
        "name": "Trance",
        "like": "NO"
    },  etc....

Here is my code;

    $data = array(
    "apiVersion"=>"1.0",
    "status"=> "ok"
);

$i = 0;
foreach ($exploded as $item) {
    $e_row[] = array(
        "id" => $i,
        "name" => $item,
        "like" => "NO"     
    );
    $i = $i + 1;
} 

array_push($data,$e_row);

header('Content-type:application/json;charset=utf-8');
echo json_encode($data, JSON_PRETTY_PRINT);  
HeavyHead
  • 310
  • 3
  • 11

0 Answers0