php - Convert Azure Table storage entities to JSON -


is there way convert azure table storage entities json?

the azure entity object in php has lot of meta data. there way clean it, , return json object relevant data.

the entity object prints this

windowsazure\table\models\entity object         (             [_etag:windowsazure\table\models\entity:private] => w/"datetime'2013-10-07t04%3a19%3a37.0155205z'"             [_properties:windowsazure\table\models\entity:private] => array                 (                     [partitionkey] => windowsazure\table\models\property object                         (                             [_edmtype:windowsazure\table\models\property:private] =>                              [_value:windowsazure\table\models\property:private] => weather                         )                      [rowkey] => windowsazure\table\models\property object                         (                             [_edmtype:windowsazure\table\models\property:private] =>                              [_value:windowsazure\table\models\property:private] => 0d625293-ef40-492b-bf07-d2889597a8f4                         )                      [timestamp] => windowsazure\table\models\property object                         (                             [_edmtype:windowsazure\table\models\property:private] => edm.datetime                             [_value:windowsazure\table\models\property:private] => datetime object                                 (                                     [date] => 2013-10-07 04:19:37                                     [timezone_type] => 3                                     [timezone] => utc                                 )                          )                      [type] => windowsazure\table\models\property object                         (                             [_edmtype:windowsazure\table\models\property:private] => edm.int32                             [_value:windowsazure\table\models\property:private] => 1                         )                      [city] => windowsazure\table\models\property object                         (                             [_edmtype:windowsazure\table\models\property:private] =>                              [_value:windowsazure\table\models\property:private] => pune                         )                       [temperature] => windowsazure\table\models\property object                         (                             [_edmtype:windowsazure\table\models\property:private] => edm.int32                             [_value:windowsazure\table\models\property:private] => 34.7                         )                      [localtime] => windowsazure\table\models\property object                         (                             [_edmtype:windowsazure\table\models\property:private] =>                              [_value:windowsazure\table\models\property:private] => 2013-10-07t04:19:31.724z                         )                  )          ) 

i have clean json output this

{    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" } 

i have implemented loop achieve this. i'm not sure if best way it.

$entities = $result->getentities();         $jsonarray = array();          ($i = 0; $i < count($entities); $i++) {             $arr = $entities[$i]->getproperties();             $temparr = array();             foreach ($arr $key => $value) {                 if(gettype($entities[$i]->getpropertyvalue($key)) != 'object'){                      $temparr[$key] = (string)$entities[$i]->getpropertyvalue($key);                 }                 else                 {                      $temparr[$key] = serialize($entities[$i]->getpropertyvalue($key));                 }             }             array_push($jsonarray, $temparr);         }         echo json_encode($jsonarray); 

i think have answered own question :). have recommended same approach i.e. loop on properties array , create json representation out of it.

one thing want mention json not natively supported in windows azure tables coming (it demonstrated in //build conference in july). when happens, able directly request table storage return data in json format , not go through conversion exercise. till time, think approach need follow.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -