Reputation: 3215
I need to parse an output of JSON from Azure Table Storage. I am able to retrieve the data, but the JSON retuned appears to give me an array per entry of data instead of an expected single array. NOTE: a true array should have the [] around it, so I am unsure on how to output/display this data as I can't seem to reach the values nested.
My call to the table to get results is as follows:
var options = { payloadFormat: "application/json;odata=nometadata" };
tableService.queryEntities('myTable', tableQuery, null, options, function(error, result, response) {
if(!error) {
console.log(response.body.value);
}
Ex. I expect this per https://blogs.msdn.microsoft.com/windowsazurestorage/2013/12/05/windows-azure-tables-introducing-json/:
"value":[
{
"PartitionKey":"Jonathan",
"RowKey":"Foster",
"Timestamp":"2013-12-03T06:45:00.7254269Z",
"Address":"1234 SomeStreet St, Bellevue, WA 75001",
"Email":"[email protected]",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2005-01-05T00:00:00Z",
"Rating":3
},
{
"PartitionKey":"Lisa",
"RowKey":"Miller",
"Timestamp":"2013-12-03T06:45:00.8834427Z",
"Address":"4567 NiceStreet St, Seattle, WA 54332",
"Email":"[email protected]",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2003-01-05T00:00:00Z",
"Rating":2
},
{
"PartitionKey":"Walter",
"RowKey":"Harp",
"Timestamp":"2013-12-03T06:45:00.5384082Z",
"Address":"1345 Fictitious St, St Buffalo, NY 98052",
"Email":"[email protected]",
"PhoneNumber":"425-555-0101",
"CustomerSince":"2010-01-05T00:00:00Z",
"Rating":4
}
]
}
But I am getting this:
{value: Array(8)}
value: Array(8)
0: {PartitionKey: "Client1", RowKey: "1", Timestamp: "2019-06-05T14:07:08.5541163Z", Location: "eastus", OSType: "WindowsServer", …}
1: {PartitionKey: "Client1", RowKey: "2", Timestamp: "2019-06-04T21:23:42.1804373Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
2: {PartitionKey: "Client1", RowKey: "3", Timestamp: "2019-06-04T21:23:42.2394792Z", PowerState: "VM deallocated", OSType: "SQL2016SP1-WS2016", …}
3: {PartitionKey: "Client1", RowKey: "4", Timestamp: "2019-06-04T21:23:42.2104586Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
4: {PartitionKey: "Client1", RowKey: "5", Timestamp: "2019-06-04T21:23:42.2674991Z", PowerState: "VM running", OSType: "WindowsServer", …}
5: {PartitionKey: "Client1", RowKey: "6", Timestamp: "2019-06-04T21:23:42.3045253Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
6: {PartitionKey: "Client1", RowKey: "7", Timestamp: "2019-06-04T21:23:42.3325452Z", PowerState: "VM deallocated", OSType: "WindowsServer", …}
7: {PartitionKey: "Client1", RowKey: "8", Timestamp: "2019-06-04T21:23:42.3665693Z", PowerState: "VM deallocated", OSType: "SQL2017-WS2016", …}
length: 8
__proto__: Array(0)
__proto__: Object
Upvotes: 1
Views: 526
Reputation: 3169
You're asking for the raw json string, but that library call is giving you the parsed json object. If you want the string, just call JSON.stringify() on the object:
var str = JSON.stringify(response.body.value);
The source for the TableService.queryEntities is at https://github.com/Azure/azure-storage-node/blob/1e315487b8801b8357b8974c7d925313cb143483/lib/services/table/tableservice.js#L811
Upvotes: 3