<div class="gmail_quote">On Mon, Apr 13, 2009 at 12:19 PM, "Martin v. Löwis" <span dir="ltr"><<a href="mailto:martin@v.loewis.de">martin@v.loewis.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">> I use the json module in 2.6 to communicate with a C# JSON library and a<br>
> JavaScript JSON library. The C# and JavaScript libraries produce and<br>
> consume the equivalent of str, not the equivalent of bytes.<br>
<br>
</div>I assume there is a TCP connection between the json module and the<br>
C#/JavaScript libraries?<br>
</blockquote><div><br>Yes, there's a TCP connection. Sorry for not making that clear to begin with.<br><br>I also sometimes store JSON objects in a database. In that case, I pass strings to the database API which stores them in a TEXT field. Obviously somewhere they get encoding to bytes, but that's handled by the database.<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">If so, it doesn't matter what representation these implementations chose<br>
to use.</blockquote><div><br></div></div>True, I can always convert from bytes to str or vise versa. Sometimes it is illustrative to see how others have chosen to solve the same problem. The JSON specification and other implementations serializes an object to a string. Python's json.dumps() needs to either return a str or let the user specify an encoding.<br>
<br>At least one of these two needs to work:<br><br>json.dumps({}).encode('utf-16le') # dumps() returns str<br>'{\x00}\x00'<br><br>json.dumps({}, encoding='utf-16le') # dumps() returns bytes<br>
'{\x00}\x00'<br><br>In 2.6, the first one works. The second incorrectly returns '{}'.<br>
<blockquote style="margin: 1.5em 0pt;">--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</blockquote>