title: Python Load UTF-8 JSON
body: <p>I have the following JSON (for simplicity's sake I'll only use one but there are 100 entries in reality):</p>
  
  <pre><code>{
      "Active": false, 
      "Book": "US Derivat. London, Mike Übersax/Michael Jealous", 
      "ExpirationDate": "2006-10-12", 
      "Isin": "CH0013096497", 
      "IssueDate": "2001-10-09", 
      "KbForXMonths": "0", 
      "KbPeriodDay": "Period", 
      "KbType": "Prozent", 
      "KbYear": "0.5", 
      "Keyinvest_IssueRetro": "0.50%", 
      "Keyinvest_RecurringRetro": "1.00% pro rata temporis", 
      "Keyinvest_RetroPayment": "Every month", 
      "LastImportDate": "2008-12-31", 
      "LiberierungDate": "1900-01-01", 
      "NominalCcy": "USD", 
      "NominalStueck": "5,000", 
      "PrimaryCCR": "0", 
      "QuoteType": "Nominal", 
      "RealValor": "0", 
      "Remarks": "", 
      "RwbeProductId_CCR": "034900", 
      "RwbeProductId_EFS": "034900", 
      "SecName": "Cliquet GROI on Nasdaq", 
      "SecType": "EQ", 
      "SubscriptionEndDate": "1900-01-01", 
      "TerminationDate": "2003-10-19", 
      "TradingCcy": "USD", 
      "Valor": 1309649
  }
  </code></pre>
  
  <p>I'm trying to read this JSON in order to save it as a .csv (so that I can import it into a database)</p>
  
  <p>However when i try to write this JSON data as a csv like so:</p>
  
  <pre><code>with codecs.open('EFSDUMP.csv', 'w', 'utf-8-sig') as csv_file:
      content_writer = csv.writer(csv_file, delimiter=',')
      content_writer.writerow(data.values())
  </code></pre>
  
  <p>I get an error:</p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\xdc' in position 25: ordinal not in range(128)
  </code></pre>
  
  <p>That is because there's an umlaut in the JSON (see attribute "Book").</p>
  
  <p>I try to read the JSON like this:</p>
  
  <pre><code>data = json.loads(open('EFSDUMP.json').read().decode('utf-8-sig'))
  </code></pre>
  
  <p>What's interesting is that this:</p>
  
  <pre><code>print data
  </code></pre>
  
  <p>Gives me this:</p>
  
  <pre><code>{u'PrimaryCCR': u'0', u'SecType': u'EQ', u'Valor': 1309649, u'KbType': u'Prozent', u'Book': u'US Derivat. London, Mike \xdcbersax/Michael Jealous', u'Keyinvest_RecurringRetro': u'1.00% pro rata temporis', u'TerminationDate': u'2003-10-19', u'RwbeProductId_CCR': u'034900', u'SubscriptionEndDate': u'1900-01-01', u'ExpirationDate': u'2006-10-12', u'Keyinvest_RetroPayment': u'Every month', u'Keyinvest_IssueRetro': u'0.50%', u'QuoteType': u'Nominal', u'KbYear': u'0.5', u'LastImportDate': u'2008-12-31', u'Remarks': u'', u'RealValor': u'0', u'SecName': u'Cliquet GROI on Nasdaq', u'Active': False, u'KbPeriodDay': u'Period', u'Isin': u'CH0013096497', u'LiberierungDate': u'1900-01-01', u'IssueDate': u'2001-10-09', u'KbForXMonths': u'0', u'NominalCcy': u'USD', u'RwbeProductId_EFS': u'034900', u'TradingCcy': u'USD', u'NominalStueck': u'5,000'}
  </code></pre>
  
  <p>Clearly the umlaut became a '\xdc'</p>
  
  <p>However when I do this:</p>
  
  <pre><code>print data['Book']
  </code></pre>
  
  <p>Meaning I access the attribute directly, I get:</p>
  
  <pre><code>US Derivat. London, Mike Übersax/Michael Jealous
  </code></pre>
  
  <p>So the umlaut is an actual umlaut again.</p>
  
  <p>I'm pretty sure that the JSON is UTF-8 without BOM (Notepad++ claims so)</p>
  
  <p>I have already tried all of the suggestions here without any success:
  <a href="https://stackoverflow.com/questions/13156395/python-load-json-file-with-utf-8-bom-header">Python load json file with UTF-8 BOM header</a></p>
  
  <p>How can I properly read the UTF-8 JSON file in order to be able to write it as .csv?</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Python version: 2.7.2</p>