title: Convert array to particular JSON format
body: <p>I am kicking my self for having to ask this question, but I cannot figure out how to convert the following array to the JSON format below. Simply <code>json_encoding</code> the array does not produce the square brackets needed.</p>
  
  <p>PHP Array</p>
  
  <pre><code>$json = array(
                "api_key" =&gt; $api_key,
                "data"    =&gt; array(
                                  "item" =&gt; array (
                                                  "value" =&gt; rand(0, 5684),
                                                  "text" =&gt; "Total"
                                                  )
                                  )
               );
  </code></pre>
  
  <p>JSON format required</p>
  
  <pre><code>{
      "api_key": "api key",
      "data": {
          "item": [
              {
                  "value": 3212,
                  "text": "Total"
              }
          ]
      }
  }
  </code></pre>
  
  <p>How should I change the array to make json_encode produce the correct format, or is there some switch I am missing on the encoding?</p>