Zedkay22 Zedkay22 - 1 month ago 9
JSON Question

PHP array curly brackets instead of square brackets

I'm attempting to output curly brackets from my array like this:


but I keep getting square brackets:


Here is my code:

$output["contextOut"] = array(array("name" => "$next-context", "parameters" =>
array("param1" => $param1value, "param2" => $param2value)));
$output["speech"] = $outputtext;
$output["data"] = array("facebook" => array("message"));
$output["displayText"] = $outputtext;
$output["source"] = "index.php";
echo json_encode($output);

and this is my json encoded output:


How do I obtain the curly brackets instead of the square brackets? Thanks in advance for any help.


As Paul Crovella said, your stated goal is invalid JSON.

Your valid options are for the facebook property to directly contain the message string:


(note I've added the outer { and } missing from your question) ...in which case you want:

$output["data"] = array("facebook" => "message");

Or you can make facebook refer to an object with a message property that has a value, like this:


by doing this:

$output["data"] = array("facebook" => array("message" => "value"));