title: Python - Changing the accent characters in a JSON file to a regular character
body: <p>I currently have a JSON file that I am trying to load in python, however because of accent characters I am getting errors. </p>
  
  <p>Is there a way for me to replace the accent characters to regular characters before doing the load? </p>
  
  <p>I tried all methods with encoding to UTF-8 based on other post suggestions. 
  Eg: </p>
  
  <pre><code>json.loads(line.decode("utf-8","ignore"))
  </code></pre>
  
  <p>or </p>
  
  <pre><code>with open("test.json", encoding='utf-8') as data_file:                           
      data = json.load(data_file)
  </code></pre>
  
  <p>Since none of these options worked, I wanted to see if there is a method to replace the accent character.</p>
  
  <p>Sample code: </p>
  
  <pre><code>import csv
  import json
  
  infile = open("infile.json","r") 
  outfile = open("outfile.csv", "w") 
  
  writer = csv.writer(outfile)
  readin = json.loads(infile.read())
  count = 1
  
  for row in readin["entry1"]["entry2"]:
  
      if count == 1:
          writer.writerow(row.keys())
          count = count + 1
  
      writer.writerow(row.values())
  
  outfile.close()
  </code></pre>
  
  <p>The above works, ONLY if there are absolutely no accent characters. </p>
  
  <p>sample JSON file: </p>
  
  <pre><code>{
    "entry1": {
      "entry2": [
        {
          "firstName": "Sam",
          "lastName": "XXX"
        },
        {
          "firstName": "Jose",
          "lastName": "Peña"
        }
      ]
    }
  }
  </code></pre>
  
  <p>I would like my output file to look like this:</p>
  
  <pre><code>firstName, lastName
  Sam,XXXX
  Jose,Peña
  </code></pre>
  
  <p>As you can see there is an accented ñ that I keep getting an error with.  Below is a sample error: </p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/Mac/Desktop/fileconversion.py", line 8, in &lt;module&gt;
      readin = json.loads(infile.read())
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
      return codecs.ascii_decode(input, self.errors)[0]
  **UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1868: ordinal not in range(128)**
  </code></pre>
  
  <p>Appreciate any help.</p>
  
  <p>Thank you. </p>