azure table how to create the table and add json data using javascript

I am trying to write a javascript function that will do two things
1st create a table in azure if it doesnt already exist

and 2nd add a row to the table I just created

I dont know how to do the following:
  1 - pass the name of the table to the azure function that creates the table I put the value in a variable TName and passed that to the function , but I could not get this to work and I had to hard code the name as a temp fix

  2 - how to create the azure table with the data that is in the json

I have tried to look for examples and I just need a very simple example that I can then make the appropriate changes ...

below i where I have got to and any help is really appreciated

example of the json data I am passing to the function:

Open in new window

// here is the function I am trying to build
function (context, iJsonData) {
    var azureStorage = require('azure-storage');    
    var AzureEnv = process.env.test_storage;

	var tableService = azureStorage.createTableService(process.env.test_storage);

// get the season ticket data to be loaded  
    var ClientData = iJsonData; 

	var TName = "MyTestTable";

// how to pass TName to the function createTableIfNotExists ???
tableService.createTableIfNotExists('TEST1', function(error, result, response) {
  if(!error) { 
            context.log("Table "+TName+ " created since it did not exist");
            context.log("Table "+TName+ " already exists");

          context.log("result ");
          context.log("response ");
          context.log("Table "+TName+ " had an error while creating the table");
          context.log("result ");
          context.log("response ");

//How to define the structure of the azure table????

// How to insert the data that is in the json to the table ???


Open in new window

Jayesh AcharyaTechnichal ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

how to pass TName to the function createTableIfNotExists ???
tableService.createTableIfNotExists(TName, function(error, result, response) {

Open in new window

How to define the structure of the azure table????
Table: A table is a collection of entities. Tables don't enforce a schema on entities, which means a single table can contain entities that have different sets of properties. The number of tables that a storage account can contain is limited only by the storage account capacity limit.

How to insert the data that is in the json to the table ???
From what I read from here, the following should work :
var entGen = azure.TableUtilities.entityGenerator;
var task = {
  PartitionKey: entGen.String('hometasks'),
  RowKey: entGen.String('1'),
  description: entGen.String('take out the trash'),
  dueDate: entGen.DateTime(new Date(Date.UTC(2015, 6, 20))),
var account = {
 PartitionKey: entGen.String('accounts'),
 RowKey: entGen.String('1234'),
tableSvc.insertEntity(TName, account, function (error, result, response) {
    // Entity inserted

Open in new window

please read note about PartitionKey and RowKey on this page :

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.