Python Forum
Dealing with a .json nightmare... ideas?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dealing with a .json nightmare... ideas?
#1
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?
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
Reply


Messages In This Thread
Dealing with a .json nightmare... ideas? - by t4keheart - Jan-27-2020, 10:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel from SAP - dealing with formats and VBA MasterOfDestr 7 635 Feb-25-2024, 12:23 PM
Last Post: Pedroski55
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 943 Jan-18-2023, 10:02 PM
Last Post: snippsat
  UnicodeEncodeError - Dealing with Japanese Characters fioranosnake 2 2,510 Jul-07-2022, 08:43 PM
Last Post: fioranosnake
  Help with coding/ideas natalie 6 1,877 Feb-12-2022, 03:16 PM
Last Post: deanhystad
  Dealing with duplicated data in a CSV file bts001 10 11,645 Sep-06-2021, 12:11 AM
Last Post: SamHobbs
  Looking for some ideas - Radius Log moralear27 1 1,972 Sep-10-2020, 09:32 PM
Last Post: micseydel
  Dealing with Exponential data parthi1705 11 9,877 May-30-2019, 10:16 AM
Last Post: buran
  some ideas for intelligent list splitting? wardancer84 4 3,233 Nov-20-2018, 02:47 PM
Last Post: DeaD_EyE
  Dealing with multiple context managers heras 5 4,747 Nov-16-2018, 09:01 AM
Last Post: DeaD_EyE
  dealing with big data of timestamp LMQ 0 2,185 Jul-27-2018, 01:23 PM
Last Post: LMQ

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020