Encoding string to json
===

I' ve got a problem with encoding string to json. I'm doing a google pie chart. Chart will be filled with data from database. Google chart requires data in json format.

Below is the example of a string how it supposed to look like. Now I have a problem with dynamically "assembling" the string with data from database.
Please help.

    <?php 

     $db=new DB();
     $db->connect();
     $db->selectBase();

     $rows = array();
     $sth=$db->st_glede_na_tip() or die(mysql_error());
     while($r = mysql_fetch_assoc($sth)) {
     $rows[] = $r;
}


     $string= '{
         "cols": [
            {"id":"","label":"Content","pattern":"","type":"string"},
            {"id":"","label":"Slices","pattern":"","type":"number"}
           ],
        "rows": [
            {"c":[{"v":"Books"},{"v":3}]},
            {"c":[{"v":"Video"},{"v":1}]},
            {"c":[{"v":"Audio"},{"v":1}]},
            {"c":[{"v":"Movie"},{"v":1}]},
          ]
       }';

       echo $string;


     ?>