|  | @@ -4,12 +4,15 @@ import chardet
 | 
	
		
			
				|  |  |  import io
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  def extractJSON(data):
 | 
	
		
			
				|  |  | -    encoding=chardet.detect(data)["encoding"]
 | 
	
		
			
				|  |  | -    try:
 | 
	
		
			
				|  |  | -    	return json.loads(data.decode(encoding))
 | 
	
		
			
				|  |  | -    except UnicodeDecodeError:
 | 
	
		
			
				|  |  | -      print(f'Failed to decode with [{encoding}]: {data}')
 | 
	
		
			
				|  |  | -      return None
 | 
	
		
			
				|  |  | +   encoding=chardet.detect(data)["encoding"]
 | 
	
		
			
				|  |  | +   #try with a set of encodings to maximize probability of success
 | 
	
		
			
				|  |  | +   encodings=[encoding,'utf_8']
 | 
	
		
			
				|  |  | +   for x in encodings:
 | 
	
		
			
				|  |  | +      try:
 | 
	
		
			
				|  |  | +         return json.loads(data.decode(encoding))
 | 
	
		
			
				|  |  | +      except UnicodeDecodeError:
 | 
	
		
			
				|  |  | +         print(f'Failed to decode with [{encoding}]: {data}')
 | 
	
		
			
				|  |  | +   return None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class orthancDB:
 |