title: Convert Azure Table storage entities to JSON
body: <p>Is there a way to convert Azure Table storage entities to JSON?</p>
  
  <p>The Azure Entity object in PHP has a lot of meta data. Is there a good way to clean it, and return a JSON object with only the relevant data.</p>
  
  <p>The Entity object prints something like this</p>
  
  <pre><code>WindowsAzure\Table\Models\Entity Object
          (
              [_etag:WindowsAzure\Table\Models\Entity:private] =&gt; W/"datetime'2013-10-07T04%3A19%3A37.0155205Z'"
              [_properties:WindowsAzure\Table\Models\Entity:private] =&gt; Array
                  (
                      [PartitionKey] =&gt; WindowsAzure\Table\Models\Property Object
                          (
                              [_edmType:WindowsAzure\Table\Models\Property:private] =&gt; 
                              [_value:WindowsAzure\Table\Models\Property:private] =&gt; weather
                          )
  
                      [RowKey] =&gt; WindowsAzure\Table\Models\Property Object
                          (
                              [_edmType:WindowsAzure\Table\Models\Property:private] =&gt; 
                              [_value:WindowsAzure\Table\Models\Property:private] =&gt; 0d625293-ef40-492b-bf07-d2889597a8f4
                          )
  
                      [Timestamp] =&gt; WindowsAzure\Table\Models\Property Object
                          (
                              [_edmType:WindowsAzure\Table\Models\Property:private] =&gt; Edm.DateTime
                              [_value:WindowsAzure\Table\Models\Property:private] =&gt; DateTime Object
                                  (
                                      [date] =&gt; 2013-10-07 04:19:37
                                      [timezone_type] =&gt; 3
                                      [timezone] =&gt; UTC
                                  )
  
                          )
  
                      [type] =&gt; WindowsAzure\Table\Models\Property Object
                          (
                              [_edmType:WindowsAzure\Table\Models\Property:private] =&gt; Edm.Int32
                              [_value:WindowsAzure\Table\Models\Property:private] =&gt; 1
                          )
  
                      [city] =&gt; WindowsAzure\Table\Models\Property Object
                          (
                              [_edmType:WindowsAzure\Table\Models\Property:private] =&gt; 
                              [_value:WindowsAzure\Table\Models\Property:private] =&gt; Pune
                          )
  
  
                      [temperature] =&gt; WindowsAzure\Table\Models\Property Object
                          (
                              [_edmType:WindowsAzure\Table\Models\Property:private] =&gt; Edm.Int32
                              [_value:WindowsAzure\Table\Models\Property:private] =&gt; 34.7
                          )
  
                      [localTime] =&gt; WindowsAzure\Table\Models\Property Object
                          (
                              [_edmType:WindowsAzure\Table\Models\Property:private] =&gt; 
                              [_value:WindowsAzure\Table\Models\Property:private] =&gt; 2013-10-07T04:19:31.724Z
                          )
  
                  )
  
          )
  </code></pre>
  
  <p>I would like to have a clean JSON output something like this</p>
  
  <pre><code>{
     PartitionKey:"weather",
     RowKey: "0d625293-ef40-492b-bf07-d2889597a8f4",
     Timestamp: "2013-10-07 04:19:37"
     type: 1,
     city: "Pune",
     tempterature: 34.7
     localTime: "2013-10-07T04:19:31.724Z"
  }
  </code></pre>
  
  <p>I have implemented a loop to achieve this. I'm not sure if this is the best way to do it.</p>
  
  <pre><code>$entities = $result-&gt;getEntities();
          $jsonArray = array();
  
          for ($i = 0; $i &lt; count($entities); $i++) {
              $arr = $entities[$i]-&gt;getProperties();
              $tempArr = array();
              foreach ($arr as $key =&gt; $value) {
                  if(gettype($entities[$i]-&gt;getPropertyValue($key)) != 'object'){
  
                      $tempArr[$key] = (string)$entities[$i]-&gt;getPropertyValue($key);                 }
                  else
                  {
  
                      $tempArr[$key] = serialize($entities[$i]-&gt;getPropertyValue($key));
                  }
              }
              array_push($jsonArray, $tempArr);
          }
          echo json_encode($jsonArray);
  </code></pre>