Perspective table cell color

Thanks for your help. That has cleaned up the code a little. I’ll work on sorting the key order in the json string later.

output_json = []
	    
	style_red = {"backgroundColor": "red"}
	style_green = {"backgroundColor": "green"}
	style_gray = {"backgroundColor": "gray"}
	
	for row in range(value.getRowCount()):
		row_object = {}
					
		for col in value.getColumnNames():    
			cell_object = {}
			cell_style = {}
			# Add a key/value pair for the cell
			cell_object['value']=value.getValueAt(row, col)
			
			# Select the style
			if col == 'LED':
				color = value.getValueAt(row, col)
				if color == 'red':
					cell_style = style_red
				elif color == 'green':
					cell_style = style_green
				elif color == 'gray':
					cell_style = style_gray
			
			cell_object['style']=cell_style
			
			#Add the cell object to the row object
			row_object[col]=cell_object
		
		#Add the row_object to the output					
		output_json.append(row_object)	
		
	return output_json