<?php
$product = array(
'id' => 'p01',
'name' => 'name 1',
'price' => 4.5,
'category' => array(
'id' => 'c1',
'name' => 'category 1'
),
'colors' => array('red', 'green', 'blue', 'yellow')
);
header('Content-Type: application/json');
echo json_encode($product);
?>
Output
{"id":"p01","name":"name 1","price":4.5,"category":{"id":"c1","name":"category 1"},"colors":["red","green","blue","yellow"]}