Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 02:51 PM
Is there a way to parse JSON in the following format:
{
"data": [
"pmgsbx1",
"pmgsbx2",
"pmgsbx3",
"pmgsbx4",
"pmgsbx5"
]
}
I know if the JSON were like the below I could have code like the following to add options to a form:
var answer = response.responseXML.documentElement.getAttribute("answer");
var objJSON = JSON.parse(answer);
for (var loop = 0; loop < objJSON.data.length; loop++)
{
g_form.addOption('test_existing_pooled_account_text', objJSON.data[loop].name, objJSON.data[loop].name);
}
{
"data": [
{
"id": 518,
"name": "PAM-ldrpcic-1",
"pam_group": "PAM-TEST",
"request_id": "RITM0483862"
},
{
"id": 519,
"name": "PAM-ldrpcic-2",
"pam_group": "PAM-TEST",
"request_id": "RITM0483862"
},
{
"id": 520,
"name": "PAM-ldrpcic-3",
"pam_group": "PAM-TEST",
"request_id": "RITM0483862"
}]
}
But I'm stuck trying to parse an array without a key value. Any thoughts?
Solved! Go to Solution.
Labels:
- Labels:
-
Scripting and Coding
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 03:07 PM
var objJSON = JSON.parse(answer);
for (var loop = 0; loop < objJSON.data.length; loop++)
{
g_form.addOption('test_existing_pooled_account_text', objJSON.data[loop], objJSON.data[loop]);
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022
Vinod Kumar Kachineni
Community Rising Star 2022
6 REPLIES 6

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 03:52 PM
FWIW, I did something almost exactly like this on Episode 33 of TechNow.
TechNow Ep 33 | GlideAjax - Developer Community - ServiceNow Community
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 04:11 PM
Ahh, thank you very much Chuck! I’ve made it a habit to watch the TechNow episodes and your live streams but apparently didn’t go back that far. Thank you for all of the content you put out—it’s quite amazing! Cheers!