How to separate Json Array of Strings

Chinmayee1
Giga Contributor

Hi , 

I need to separate each of these below arrays into 8 separate arrays so that I can pass these to a method. Now the length shows as the length of total string and not 8.

contentMap received :[

{"column":"u_kb_index","content":"SCOM_CUSTOM_Service-Health_BY0VBV","table":"u_kb_template_gems","number":"KB0022149"},

{"column":"u_kb_source","content":"SCOM","table":"u_kb_template_gems","number":"KB0022149"},

{"column":"u_kb_monitor_description","content":"<p>QA Airwatch API Service is Down<br /><br /> <span style=\"font-family: Calibri;\">Summary: </span><br /><span style=\"font-family: Calibri;\">The Airwatch Application Service or IIS or World Wide Web Publishing Service is not running</span></p>","table":"u_kb_template_gems","number":"KB0022149"}]

Please help.

Thanks in Advance,

Chinmayee Mishra

 

1 ACCEPTED SOLUTION

So that seems to be alright now. You have 8 entries. So length is returning 8?

Then you can loop through that like:

for(var i=0;i<contentArr.length;i++){

gs.info(JSON.stringify(contentArr[i]));

//do something with the object

}

 

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can iterate over the array and send each json object as string to another function

sample below

var contentArr = []; // this is your complete array of json objects

for(var i=0;i<contentArr.length;i++){

var obj = new ScriptInclude();

obj.yourFunction(JSON.stringify(contentArr[i])); // pass the json string for the object to another function

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

contentArr.length is 5589

It should loop for 8 times only

Hi,

array should give 8 as that array contains 8 json objects

can you try printing this

gs.info('element 1' + JSON.stringify(contentArr[0]));

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Chinmayee 

it should work

I just tried this in scripts background

var arr = [

{"column":"u_kb_index","content":"SCOM_CUSTOM_Service-Health_BY0VBV","table":"u_kb_template_gems","number":"KB0022149"},

{"column":"u_kb_source","content":"SCOM","table":"u_kb_template_gems","number":"KB0022149"},

{"column":"u_kb_monitor_description","content":"<p>QA Airwatch API Service is Down<br /><br /> <span style=\"font-family: Calibri;\">Summary: </span><br /><span style=\"font-family: Calibri;\">The Airwatch Application Service or IIS or World Wide Web Publishing Service is not running</span></p>","table":"u_kb_template_gems","number":"KB0022149"}];

for(var key in arr){

gs.info('element' + JSON.stringify(arr[key]));

}

Output:

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader