title: How to output strong typed variables in JSON
body: <p>I am using PDO to output SQL results to JSON. The problem is that everything is a string, but I would like integers and booleans not to be string. Is there a way to do this?</p>
  
  <p>This is what I am doing:    </p>
  
  <pre><code>$db = getConnection();
  $stmt = $db-&gt;query('SELECT * FROM chapters');  
  $results = $stmt-&gt;fetchAll(PDO::FETCH_OBJ);
  $db = null;
  echo json_encode($results);
  </code></pre>
  
  <p>And this is what it give me:</p>
  
  <pre><code>[{"id":"1","name":"Book1","pages":"123",active:"\u0001"}]
  </code></pre>
  
  <p>But I would it to output this:</p>
  
  <pre><code>[{"id":1,"name":"Book1","pages":123,active:true}] 
  </code></pre>
  
  <p>The columns in MySQL columns are indeed ints and bits. How to I output the right types so I don't have to parse these on the client-side?</p>