- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 01:24 PM
I need to pull data from ServiceNow with Python and write it into an external database. The data is returned in this format:
{'result': [{'sys_id': '1c741bd70b2322007518478d83673af3', 'number': 'INC0000060', 'short_description': 'Unable to connect to email', 'assignment_group': {'link': 'https://dev12604.service-now.com/api/now/table/sys_user_group/287ebd7da9fe198100f92cc8d1d2154e', 'value': '287ebd7da9fe198100f92cc8d1d2154e'}}]}
How can I get that data into an array of objects that can be looped over for processing?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 01:45 PM
figured it out. I'm not familiar with python so this took longer than it should have...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 01:45 PM
figured it out. I'm not familiar with python so this took longer than it should have...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 01:45 PM
- If you are using the Requests Python library (https://docs.python-requests.org/en/latest/user/quickstart/), please note that it has a build-in JSON parser
- If you are trying to pull data ServiceNow and write it into an external database, please note that there is an open-source application that does that very thing here: https://github.com/gflewis/sndml3

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 01:45 PM
print(data['result][0]) should work
Please mark my answer as helpful/correct if it has helped

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2022 03:19 PM
Something like the following. It's better to use .get() to avoid exception in case the key doesn't exists in the dictionary.
def test01():
data = {'result': [{'sys_id': '1c741bd70b2322007518478d83673af3', 'number': 'INC0000060', 'short_description': 'Unable to connect to email', 'assignment_group': {'link': 'https://dev12604.service-now.com/api/now/table/sys_user_group/287ebd7da9fe198100f92cc8d1d2154e', 'value': '287ebd7da9fe198100f92cc8d1d2154e'}}]}
data_list = data.get('result')
for row in data_list:
print(f'sys_id:{row.get("sys_id")}, number:{row.get("number")}, short_description:{row.get("short_description")}')
if __name__ == '__main__':
test01()
Execution result:
sys_id:1c741bd70b2322007518478d83673af3, number:INC0000060, short_description:Unable to connect to email