Trying to recreate new dicitonary from loop of API returned dictionary

The 'Pythonic' way to construct a repetitive list like this would be a comprehension. I suspect that you actually want your return to be a list of objects, not deeply nested objects as your code sample implies. Try this:

def runAction(self):
	system.perspective.print( "Page Script Started" )
	client = system.net.httpClient()
	response = client.get("https://api.megamation.com/clm/DL/workorder?STATUS=S&TYPE=PM&BUILDING_ID=Climatemaster", username="<>", password="<>")
	
	self.custom.getPMOrders = [
		{
			'date': key['date'],
			'building_id': key['building_id'],
			'wo_no': key['wo_no'],
			'work_request_description': key['work_request_description'],
			'type': key['type'],
		}
		for key in response.json['_embedded']['WorkOrder']
	]
2 Likes