Search code examples
node.jsazure-storageazure-functionsazure-table-storage

Weird JSON structure reading from Azure Table Storage


I'm reading data from my Azure Storage Table using the azure-storagemodule inside an Azure Function.

Getting the rows like this

var tableSvc = azure.createTableService();
var query = new azure.TableQuery().top(1000);
tableSvc.queryEntities('tablename', query, null, function(error, result, response) {
    // work with result.entries
}

the resulting Object looks weird as each column value is being put into it's own object with a "_" key, so the JSON looks like this:

{
    "PartitionKey": {
        "$": "Edm.String",
        "_": "Keyname"
    },
    "RowKey": {
        "$": "Edm.String",
        "_": "Keyname"
    },
    "Title": {
        "_": "The Item Title"
    }
}

instead of what I would expect:

{
    "PartitionKey": "Keyname",
    "RowKey": "Keyname",
    "Title": "The Item Title"
}

The table looks normal in the Azure Storage Explorer. Is this normal? Or can I somehow influence the output of the query?


Solution

  • You could specify the payload format as application/json;odata=nometadata and then get the resulting Object via response.body.value.

    var options = { payloadFormat: "application/json;odata=nometadata" };
    tableSvc.queryEntities('tablename', query, null, options, function(error, result, response) {
        if(!error) {
            console.log(response.body.value);
        }
    }