json_encode($thearray, JSON_FORCE_OBJECT)
<?php
// the php array
$array = array();
$array['key1'] = "value1";
$array['key2'] = "value2";
$array['key3'] = "value3";
// encode the php array into JSON format
$json = json_encode($array);
// check out the results
var_dump($json);
?>
<?php
echo json_encode(array("statusCode"=>201,"system"=>1));
?>
$person = array(
"name" => "Johny Carson",
"title" => "CTO"
);
$personJSON=json_encode($person);//returns JSON string
=====================================================
$function = "#!!function(){}!!#";
$message = "Hello";
$json = array(
'message' => $message,
'func' => $function
);
$string = json_encode($json);
$string = str_replace('"#!!','',$string);
$string = str_replace('!!#"','',$string);
echo $string;
<?php
$age = array("Peter"=>35, "Ben"=>37, "Joe"=>43);
echo json_encode($age);
?>