title: Python 2.7 JSON dump UnicodeEncodeError
body: <p>I have a file where each line is a json object like so:</p>
  
  <pre><code>{"name": "John", ...}
  
  {...}
  </code></pre>
  
  <p>I am trying to create a new file with the same objects, but with certain properties removed from all of them.</p>
  
  <p>When I do this, I get a UnicodeEncodeError. Strangely, If I instead loop over <code>range(n)</code> (for some number n) and use <code>infile.next()</code>, it works just as I want it to.</p>
  
  <p>Why so? How do I get this to work by iterating over <code>infile</code>? I tried using <code>dumps()</code> instead of <code>dump()</code>, but that just makes a bunch of empty lines in the <code>outfile</code>.</p>
  
  <pre><code>with open(filename, 'r') as infile:
      with open('_{}'.format(filename), 'w') as outfile:
          for comment in infile:
              decodedComment = json.loads(comment)
              for prop in propsToRemove:
                  # use pop to avoid exception handling
                  decodedComment.pop(prop, None)
              json.dump(decodedComment, outfile, ensure_ascii = False)
              outfile.write('\n')
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\U0001f47d' in position 1: ordinal not in range(128)
  </code></pre>
  
  <p>Thanks for the help!</p>