Home > Net >  Trying to Parse a JSON using Python but having issues
Trying to Parse a JSON using Python but having issues

Time:03-13

I usually use Powershell and have parsed JSONs from HTTP requests, successfully, before. I am now using Python and using the 'Requests' library. I have successfully got the JSON from the API. Here is the format it came through in (I removed some information and other fields).:

{'content': [
    {
    'ContactCompany': Star,
    'ContactEmail': [email protected],
    'ContactPhoneNumber': 123-456-7894, 
     'assignedGroup': 'TR_Hospital', 
     'assignedGroupId': 'SGP000000132297',  
     'serviceClass': None, 'serviceReconId': None
     }
            ]
}

I'm having trouble getting the values inside of the 'content.' With my Powershell experience in the past, I've tried:

tickets_json = requests.get(request_url, headers=api_header).json()

Tickets_Info = tickets_json.content

for tickets in tickets_info: tickets.assignedGroup

How do I parse the JSON to get the information inside of 'Content' in Python?

CodePudding user response:

tickets_json = requests.get(request_url, headers=api_header).json()

tickets_info = tickets_json['content']

for tickets in tickets_info: 
    print(tickets['assignedGroup'])
  • Related