Creating a JSON data object
Hi,
I have to create a message that looks like following within Javascript. I am unable to create the portion where, "serviceDesc" addition.
- {
- "applicationName":"Tesing",
- "projAccNumber" : "TG",
- "queueName" : "development",
- "exeuctableLocation" : "/bin/echo",
- "scratchWorkingDirectory" : "/tmp",
- "cpuCount":"12",
- "hostdescName":"localhost",
- "maxMemory":"0",
- "maxWallTime":"0",
- "minMemory":"0",
- "nodeCount":"1",
- "processorsPerNode":"12",
- "serviceDesc":{
- "serviceName" : "service1",
- "inputParams":[
- {
- "dataType":"input",
- "description":"my input",
- "name":"myinput",
- "type":"String"
- },
- {
- "dataType":"input",
- "description":"my input",
- "name":"myinput",
- "type":"String"
- }
- ],
- "outputParams":[
- {
- "dataType":"output",
- "description":"my output",
- "name":"myoutput",
- "type":"String"
- },
- {
- "dataType":"output",
- "description":"my output",
- "name":"myoutput",
- "type":"String"
- }
- ]
- }
- }
My javascript code looks like below. The issue happens when I create the part to add "serviceDesc" portion. What am I missing here and how can I create the specific message.
- var jsonRequest = {};
- jsonRequest["name"] = "appName";
- jsonRequest["executablePath"] = "exeuctableLocation";
- jsonRequest["workingDir"] = "scratchWorkingDirectory";
- jsonRequest["cpuCount"] = "cpuCount";
- jsonRequest["hostdescName"] = "hostName";
- jsonRequest["maxMemory"] = "maxMemory";
- jsonRequest["maxWallTime"] = "10";
- jsonRequest["minMemory"] = "4";
- jsonRequest["nodeCount"] = "nodeCount";
- jsonRequest["processorsPerNode"] = "3";
- var inArray = [];
- for(var j=1; j<inputCount+1; j++) {
- var input = {};
- input["dataType"] = "input";
- input["description"] = "empty";
- input["name"] = "name"; //$("#inputName" + j+1).val();
- input["type"] = "type"; //$("#inputType" + j+1).val();
- inArray[j-1] = JSON.stringify(input);
- }
- var outArray = new Array();
- for(j=1; j<outputCount+1; j++) {
- var output = {};
- output["dataType"] = "output";
- output["description"] = "empty";
- output["name"] = "name"; //$("#outputName" + j+1).val();
- output["type"] = "type"; //$("#outputType" + j+1).val();
- outArray[j-1] = JSON.stringify(output);
- }
- var serviceDesc = {};
- serviceDesc["inputParams"] = inArray;
- serviceDesc["outputParams"] = outArray;
- jsonRequest["serviceDesc"] = serviceDesc;
- console.log(JSON.stringify(jsonRequest));