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

@Chinmayee 

Glad to know that you got the approach.

Did you mistakenly mark other answer as correct?

As I see same comments were provided before from my end above pretty well (first).

You can only mark 1 response as correct. I am not against marking other answer as correct.

Please mark appropriate response as correct.

Regards
Ankur

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

Seems fine, I was first with the correct parsing and handling. So it was marked Correct accordingly. Does not seem like a mistake to me.

Hi Ankur,

In my email I first got Willem's response and tried. It worked and hence I marked his response as correct. Please don't feel bad. It would be unfair to him if I remove "correct" marking from his response.

You are a genius and I have so many more questions to come. 😛

Thank you so much for helping us.

No worries.

Have a nice day

Regards
Ankur

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

Willem
Giga Sage
Giga Sage

If it returns length of all characters, it might not be in the right format.

(assuming contentMap is the name of the variable that stores the array(like) value)

Can you log: typof contentMap

 

Try converting it by parsing it:

var arrayA = JSON.parse(contentMap);

 

And then getting the length:

arrayA.length

 

With that you can loop through it and use each individual result as you please.