- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 12:04 AM
Hi, I got this Response Body from a API call I made to another ServiceNow Instance.
{"result":[{"calendar_integration":"1","country":"","user_password":"U3X0xj01Fr","last_login_time":"","source":"","sys_updated_on":"2023-12-11 12:27:28","building":"","web_service_access_only":"true","notification":"2","enable_multifactor_authn":"false","sys_updated_by":"system","sys_created_on":"2023-06-25 12:00:57","sys_domain":{"link":"https://dev180310.service-now.com/api/now/table/sys_user_group/global","value":"global"},"state":"","vip":"false","sys_created_by":"system","zip":"","home_phone":"","time_format":"","last_login":"","default_perspective":"","active":"true","sys_domain_path":"/","cost_center":"","phone":"","name":"Virtual Agent","employee_number":"","password_needs_reset":"false","gender":"","city":"","failed_attempts":"","user_name":"virtual.agent","roles":"","title":"","sys_class_name":"sys_user","sys_id":"4583e347b4672110320f8dc279c804bb","federated_id":"MApWBRP6bOMaUi1JwFN32jJhX72bItv8zP0QwSsOdUQ=","internal_integration_user":"false","ldap_server":"","mobile_phone":"","street":"","company":"","department":"","first_name":"Virtual","email":"","introduction":"","preferred_language":"","manager":"","locked_out":"false","sys_mod_count":"3","last_name":"Agent","photo":"","avatar":"","middle_name":"","sys_tags":"","time_zone":"","schedule":"","date_format":"","location":""}]}
But when I tried to parse this using JSON.parse() method, it just returns as [object Object]. whats the issue here?
Code I Used to call Rest message from BR-
Please pour your suggestions into this. Thank you!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 03:03 AM - edited 12-15-2023 03:04 AM
Hi @Madhan007 , Can you try below?
var responseOBJ = JSON.parse(responseBody);
var name = responseOBJ.result[0].name; // To parse name
Regards,
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 03:19 AM
Hi @Madhan007
You can access the state field in the same way.
Let me give you the structure of JSON in a better way.
It first contain an object then with key result and value to this key is an array with one element which is again an object, so it will always be parsed like obj.result[0].state etc.
{
"result": [
{
"calendar_integration": "1",
"country": "",
"user_password": "U3X0xj01Fr",
"last_login_time": "",
"source": "",
"sys_updated_on": "2023-12-11 12:27:28",
"building": "",
"web_service_access_only": "true",
"notification": "2",
"enable_multifactor_authn": "false",
"sys_updated_by": "system",
"sys_created_on": "2023-06-25 12:00:57",
"sys_domain": {
"link": "https://dev180310.service-now.com/api/now/table/sys_user_group/global",
"value": "global"
},
"state": "",
"vip": "false",
"sys_created_by": "system",
"zip": "",
"home_phone": "",
"time_format": "",
"last_login": "",
"default_perspective": "",
"active": "true",
"sys_domain_path": "/",
"cost_center": "",
"phone": "",
"name": "Virtual Agent",
"employee_number": "",
"password_needs_reset": "false",
"gender": "",
"city": "",
"failed_attempts": "",
"user_name": "virtual.agent",
"roles": "",
"title": "",
"sys_class_name": "sys_user",
"sys_id": "4583e347b4672110320f8dc279c804bb",
"federated_id": "MApWBRP6bOMaUi1JwFN32jJhX72bItv8zP0QwSsOdUQ=",
"internal_integration_user": "false",
"ldap_server": "",
"mobile_phone": "",
"street": "",
"company": "",
"department": "",
"first_name": "Virtual",
"email": "",
"introduction": "",
"preferred_language": "",
"manager": "",
"locked_out": "false",
"sys_mod_count": "3",
"last_name": "Agent",
"photo": "",
"avatar": "",
"middle_name": "",
"sys_tags": "",
"time_zone": "",
"schedule": "",
"date_format": "",
"location": ""
}
]
}
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 03:03 AM - edited 12-15-2023 03:04 AM
Hi @Madhan007 , Can you try below?
var responseOBJ = JSON.parse(responseBody);
var name = responseOBJ.result[0].name; // To parse name
Regards,
Sunil