[]; public function __construct() { $this->data = array( 'Federico', 'Lozada', 'Mosto' ); } public function jsonSerialize() {return $this->data;} } echo json_encode(new Freddy()); //return ["Federico","Lozada","Mosto"] //PHP < 5.4 //{"data":["Federico","Lozada","Mosto"]}