title: Should I encode after json.dumps(...)?
body: <p>As I learnt, I now <em>always decode</em> user input coming to my script (a Python web server).<br>
  And I always encode output, for example when I send data to the client from the server, in a websocket connection.</p>
  
  <p>Should I do: </p>
  
  <pre><code>ws.send(json.dumps({'message' : message, 'id': i}))
  </code></pre>
  
  <p>or </p>
  
  <pre><code>ws.send(json.dumps({'message' : message, 'id': i}).encode('utf8'))
  </code></pre>
  
  <p>?</p>
  
  <p>The first seems ok in Python 2.7, because it seems that the result of <code>json.dumps(...)</code> is already encoded:</p>
  
  <pre><code>print type(json.dumps({'message' : message, 'id': i}))
  # &lt;type 'str'&gt;
  </code></pre>
  
  <h1>Question:</h1>
  
  <p><strong>Should we <code>.encode('utf8')</code> or not after a <code>json.dumps()</code> ?</strong></p>