title: Convert byte string to base64-encoded string (output not being a byte string)
body: <p>I was wondering if it is possible to convert a byte string which I got from reading a file to a string (so <code>type(output) == str</code>). All I've found on Google so far has been answers like <a href="https://stackoverflow.com/q/6375942/1256925">How do you base-64 encode a PNG image for use in a data-uri in a CSS file?</a>, which does seem like it would work in python 2 (where, if I'm not mistaken, strings were byte strings anyway), but which doesn't work in python 3.4 anymore.</p>
  
  <p>The reason I want to convert this resulting byte string to a normal string is that I want to use this base64-encoded data to store in a JSON object, but I keep getting an error similar to:</p>
  
  <pre><code>TypeError: b'Zm9v' is not JSON serializable
  </code></pre>
  
  <p>Here's a minimal example of where it goes wrong:</p>
  
  <pre><code>import base64
  import json
  data = b'foo'
  myObj = [base64.b64encode(data)]
  json_str = json.dumps(myObj)
  </code></pre>
  
  <p>So my question is: is there a way to convert this object of type <code>bytes</code> to an object of type <code>str</code> while still keeping the base64-encoding (so in this example, I want the result to be <code>["Zm9v"]</code>. Is this possible?</p>