title: How to convert JSON to CSV? (with UTF-8 support)
body: <p>Earlier there was a question <a href="https://stackoverflow.com/q/1871524/203204">How can I convert JSON to CSV?</a> and there were lots of answers, however none of them explains how to convert non-latin1 data.</p>
  <p>Let's say I have a JSON file like the following:</p>
  <pre><code>[
      {&quot;id&quot;:123,&quot;FullName&quot;:&quot;Иванов Иван Иванович&quot;},
      {&quot;id&quot;:124,&quot;FullName&quot;:&quot;Петров Петр Петрович&quot;}
  ]
  </code></pre>
  <p>And I try to use a script like that:</p>
  <pre><code>#!/usr/bin/env python2.7
  # -*- coding: utf-8 -*-
  
  import sys
  import codecs
  import json
  import unicodecsv as csv
  
  if __name__ == '__main__':
      fin = codecs.open(sys.argv[1], encoding='utf-8')
      data = json.load(fin)
      fin.close()
  
      with codecs.open('test.csv', encoding='utf-8', mode='wb') as csv_file:
          w = csv.writer(csv_file, encoding='utf-8')
          w.writerow(data[0].keys())  # header row
      
          for row in data:
              w.writerow(row.values())
  </code></pre>
  <p>Which gives me the following error:</p>
  <blockquote>
  <p>UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position
  32: ordinal not in range(128)</p>
  </blockquote>
  <p>First of all it is not clear what is there at position 32, but the most interesting question is if there is a way to save UTF-8 encoded strings to CSV file.</p>