$sql = "SELECT CONCAT(\'[\', better_result, \']\') AS best_result FROM\n" . "(\n" . "SELECT GROUP_CONCAT(\'{\', my_json, \'}\' SEPARATOR \',\') AS better_result FROM\n" . "(\n" . " SELECT \n" . " CONCAT\n" . " (\n" . " \'\"name_field\":\' , \'\"\', nome , \'\"\', \',\' \n" . " \'\"address_field\":\', \'\"\', cognome, \'\"\', \',\'\n" . " \'\"contact_age\":\' , mail\n" . " ) AS my_json\n" . " FROM dati\n" . ") AS more_json\n" . ") AS yet_more_json";