May be there's a reason to file another bug on Zend_Json_Encoder's _encodeString method?
By the way, give a glance at FirePHP's main standalone class "FirePHP.class.php" and its "json_encode" method. It actually does the job right! May be ZJE->_encodeString should follow this example?

Comments

Posted by Christoph Dorn (cadorn) on 2008-08-22T18:01:48.000+0000

That was an oversight. Thanks for pointing it out.

Posted by Christoph Dorn (cadorn) on 2008-08-22T23:22:02.000+0000

Can you add some test code that logs a message where the UTF-8 test does not display properly?

Posted by Christoph Dorn (cadorn) on 2008-08-24T12:12:35.000+0000

I have looked into json_encode and Zend_Json_Encoder in more detail.

While json_encode detects recursion, it does not silently truncate the resulting JSON string but instead throws an exception. Zend_Json_Encoder on the other hand truncates it and still returns a valid JSON string.

It is very common to have cyclical relationships in your object graph which should get JSON encoded and sent to the client in a truncated fashion.

The best solution for the encoding would be to try json_encode first and if it fails fall back to Zend_Json_Encoder. This would mean that UTF8 encoded messages cannot contain cyclical object relationships.

The alternative would be to add UTF8 encoding support to Zend_Json_Encoder which would be great, but not practical as an immediate fix for this issue.

So would the fallback approach work for now until Zend_Json_Encoder supports UTF8 characters?