title: Salesforce - Create JSON from SOQL results
body: <p>I'm using a VisualForce page to generate a JSON file that's read by a jQuery plugin. My page uses a controller to query for records and output them. Code is below:</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Solved! Here is the solution I found (credit <a href="http://blog.lopau.com/visualforce-row-count/" rel="nofollow">http://blog.lopau.com/visualforce-row-count/</a>)</p>
  
  <p>I made my opp object into a list by changing</p>
  
  <pre><code> public Opportunity opp {get; private set;}
  </code></pre>
  
  <p>to</p>
  
  <pre><code> public Opportunity[] opp {get; private set;}
  </code></pre>
  
  <p>then used an apex:repeat to loop through the values.</p>
  
  <pre><code>&lt;apex:page standardstylesheets="false" controller="myOppCon" sidebar="false" showHeader="false" contentType="application/x-JavaScript; charset=utf-8"&gt;
  [
  &lt;apex:variable value="1" var="rowNum"/&gt;
  &lt;apex:variable var="rawData" value="opp" /&gt;
  &lt;apex:repeat value="{!opp}" var="List" id="theRepeat"&gt;
  {
  "id":"{!List.id}",
  "title":"{!List.name}",
  "start":"&lt;apex:outputText value="{0,date,E',' dd MMM yyyy HH:mm:ss z}"&gt;
              &lt;apex:param value="{!List.Trip_Start_DateTime__c}" /&gt; 
           &lt;/apex:outputText&gt;",
  "end":"&lt;apex:outputText value="{0,date,E',' dd MMM yyyy HH:mm:ss z}"&gt;
              &lt;apex:param value="{!List.Trip_End_DateTime__c}" /&gt; 
           &lt;/apex:outputText&gt;",
  "url":"/{!List.id}"
  }, 
  &lt;apex:variable var="rowNum" value="{!VALUE(rowNum) + 1}"/&gt;
  &lt;/apex:repeat&gt;
  {}]
  &lt;/apex:page&gt;
  </code></pre>