I am kicking my self for having to ask this question, but I cannot figure out how to convert the following array to the JSON format below. Simply json_encoding the array does not produce the square brackets needed.
PHP Array
$json = array(
"api_key" => $api_key,
"data" => array(
"item" => array (
"value" => rand(0, 5684),
"text" => "Total"
)
)
);
JSON format required
{
"api_key": "api key",
"data": {
"item": [
{
"value": 3212,
"text": "Total"
}
]
}
}
How should I change the array to make json_encode produce the correct format, or is there some switch I am missing on the encoding?