As the comment says, you should instead use the (php function) json_encode function, which will ...
php: $a = array( array("gender"=> "male", "name"=> "Bob"), array("gender"=> "female", "name"=> "Annie") ); Into json: [ {gender:"male", name:"Bob"}, {gender:"female", name:"Annie"} ]
Echoing json_encode ($ a) prints it in exactly the same way.
source share