title: Encoding and then decoding json with non-ascii characters in python 2.7
body: <p>I have a python application that encodes some objects to json, passes the json string to another program, and then reads in a possibly modified version of that json string.  </p>
  
  <p>I need to check that what's changed with the json encoded objects. However, I'm having trouble with re-encoding non-ascii characters.  For example: </p>
  
  <pre><code>x = {'\xe2': None} # a dict with non-ascii keys
  y = json.dumps(x,ensure_ascii=False)
  y
  #&gt; '{"\xe2": null}'
  </code></pre>
  
  <p>works just fine, but when I try to load the json, I get:</p>
  
  <pre><code>json.loads(y)
  #&gt; UnicodeDecodeError: 'utf8' codec can't decode byte 0xe2 in position 0
  json.loads(y.decode('utf-8','ignore'))
  #&gt; "{u'': None}"
  json.loads(y.decode('utf-8','replace'))
  #&gt; {u'\ufffd': None}
  </code></pre>
  
  <p>and unfortunately <code>'\xe2' in {u'\ufffd': None}</code> evaluates to <code>False</code></p>
  
  <p>I'm willing to bet there is a simple solution, but all my googling and searching on SO has failed to find an adequate solution.  </p>