Jan-27-2020, 10:17 PM
Hi guys,
I'm working with an API and am dealing with a pretty large json dump. It's about 1000 lines and in there lies particular information I'm looking for. I would like to know how to best parse this information and pull what I need from it. The data all gets written to a file called 'RECdemp.json'.
Something like this?
I think what I will do to correlate sent sms messages and their replies to deliver to the proper recipient is to keep a sort of "dictionary" file with a dictionary full of who belongs to which message ID, and reference this file when delivering the response back to the sender, but first i need to sift through all this json!
Here's what some of the json looks like. The values in particular that I am interested in and would like to pull are: 'id' (first key) and 'body' (second key).
I'm working with an API and am dealing with a pretty large json dump. It's about 1000 lines and in there lies particular information I'm looking for. I would like to know how to best parse this information and pull what I need from it. The data all gets written to a file called 'RECdemp.json'.
Something like this?
collection={} r=requests.get(url, headers=h, params=p) r=str(r) for index in enumerate(r): key_name = 'col{0}.format(index) collection[key_name] = responses key1 = collection['col1'] key2 = collection['col2'] key3 = collection['col3'] return (key1, key2, key3)Now, this doesn't work... and I have no idea why it doesn't work, because I don't really understand what that block of code is doing. I use a similar for loop to parse/iterate through another file to collect specific results, but I'm not good enough yet to write these without assistance.
I think what I will do to correlate sent sms messages and their replies to deliver to the proper recipient is to keep a sort of "dictionary" file with a dictionary full of who belongs to which message ID, and reference this file when delivering the response back to the sender, but first i need to sift through all this json!
Here's what some of the json looks like. The values in particular that I am interested in and would like to pull are: 'id' (first key) and 'body' (second key).
Quote:{'id': 1005672, 'messages': [{'id': 4461048, 'body': 'Mnow test test', 'conversationId': 1005672, 'locationId': 2045, 'contactId': 12792806, 'assignedUserId': 0, 'status': 'RECEIVED', 'error': None, 'kind': 'INCOMING', 'outgoing': False, 'reviewRequest': False, 'type': 'SMS', 'readDate': 0, 'respondedDate': 0, 'sentDate': 1576783232355, 'attachments': []}, {'id': 4461049, 'body': 'THIS NUMBER DOES NOT CURRENTLY ACCEPT TEXT MESSAGES PLEASE CALL TO WORK WITH ONE OF OUR INTAKE SPECIALISTS', 'conversationId': 1005672, 'locationId': 2045, 'contactId': 12792806, 'assignedUserId': 0, 'status': 'RECEIVED', 'error': None, 'kind': 'AUTO_RESPONSE', 'outgoing': True, 'reviewRequest': False, 'type': 'SMS', 'readDate': 0, 'respondedDate': 0, 'sentDate': 1576783233546, 'attachments': []}, {'id': 4620511, 'body': 'test sms,test sms', 'conversationId': 1005672, 'locationId': 2045, 'contactId': 12792806, 'assignedUserId': 17297, 'status': 'DELIVERED', 'error': None, 'kind': 'API', 'outgoing': True, 'reviewRequest': False, 'type': 'SMS', 'readDate': 0, 'respondedDate': 0, 'sentDate': 1577987093930, 'attachments': []}, {'id': 4620584, 'body': 'test sms', 'conversationId': 1005672, 'locationId': 2045, 'contactId': 12792806, 'assignedUserId': 17297, 'status': 'DELIVERED', 'error': None, 'kind': 'API', 'outgoing': True, 'reviewRequest': False, 'type': 'SMS', 'readDate': 0, 'respondedDate': 0, 'sentDate': 1577987195228, 'attachments': []}, {'id': 4646648, 'body': 'test sms', 'conversationId': 1005672, 'locationId': 2045, 'contactId': 12792806, 'assignedUserId': 17297, 'status': 'DELIVERED', 'error': None, 'kind': 'API', 'outgoing': True, 'reviewRequest': False, 'type': 'SMS', 'readDate': 0, 'respondedDate': 0, 'sentDate': 1578083596336, 'attachments': []}, {'id': 4646877, 'body': 'test sms', 'conversationId': 1005672, 'locationId': 2045, 'contactId': 12792806, 'assignedUserId': 17297, 'status': 'DELIVERED', 'error': None, 'kind': 'API', 'outgoing': True, 'reviewRequest': False, 'type': 'SMS', 'readDate': 0, 'respondedDate': 0, 'sentDate': 1578084072306, 'attachments': []}, {'id': 4671891, 'body': 'test sms', 'conversationId': 1005672, 'locationId': 2045, 'contactId': 12792806, 'assignedUserId': 17297, 'status': 'DELIVERED', 'error': None, 'kind': 'API', 'outgoing': True, 'reviewRequest': False, 'type': 'SMS', 'readDate': 0, 'respon