Skip to content

Commit d926853

Browse files
authored
extractValueFromJSON.js
This script helps to extract data from the JSON and show the username and corresponding role(s)
1 parent be1fd1a commit d926853

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//JSON of username and corresponding title
2+
3+
var userData = {
4+
"userDetails": [{
5+
"user_name": "dennis.millar",
6+
"title": "Account Exec Northeast"
7+
},
8+
{
9+
"user_name": "ashley.parker",
10+
"title": "Director"
11+
},
12+
{
13+
"user_name": "steve.schorr",
14+
"title": "Investigations Generalist"
15+
},
16+
{
17+
"user_name": "tammie.schwartzwalde",
18+
"title": "Senior Auditor"
19+
},
20+
{
21+
"user_name": "tammie.schwartzwalde",
22+
"title": "Payroll Generalist"
23+
},
24+
{
25+
"user_name": "tommy.tom",
26+
"title": "Tester"
27+
},
28+
]
29+
};
30+
31+
var userRoles = {};
32+
for (var i = 0; i < userData.userDetails.length; i++) {
33+
var user = userData.userDetails[i];
34+
if (!userRoles[user.user_name]) {
35+
userRoles[user.user_name] = [];
36+
}
37+
38+
if (userRoles[user.user_name].indexOf(user.title) === -1) {
39+
userRoles[user.user_name].push(user.title);
40+
}
41+
}
42+
43+
44+
for (var userName in userRoles) {
45+
gs.info("User: " + userName + " having Role(s): " + userRoles[userName].join(", "));
46+
}

0 commit comments

Comments
 (0)