On Mon, Apr 13, 2009 at 12:19 PM, "Martin v. Löwis" <martin@v.loewis.de> wrote:
> I use the json module in 2.6 to communicate with a C# JSON library and a
> JavaScript JSON library.  The C# and JavaScript libraries produce and
> consume the equivalent of str, not the equivalent of bytes.

I assume there is a TCP connection between the json module and the
C#/JavaScript libraries?

Yes, there's a TCP connection.  Sorry for not making that clear to begin with.

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.
If so, it doesn't matter what representation these implementations chose
to use.

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.

At least one of these two needs to work:

json.dumps({}).encode('utf-16le')  # dumps() returns str

json.dumps({}, encoding='utf-16le')  # dumps() returns bytes

In 2.6, the first one works.  The second incorrectly returns '{}'.
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC