Reviewed & tested by the community
Project:
JSON server
Version:
6.x-2.0-alpha1
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
30 Jul 2008 at 16:21 UTC
Updated:
23 Apr 2010 at 21:09 UTC
Jump to comment: Most recent file
Comments
Comment #1
Steven Merrill commentedMy reasoning for using json_encode() if available is as a speed boost (since it's baked-in,) and also by virtue of the fact that HTML escaping does not seem to be needed in drupal_to_js() any more - see http://drupal.org/node/222578#comment-773458.
Comment #2
andremolnar commentedFurthermore the escaping done results in invalid json being returned. I'll be happy to review your patch when it lands. Internally we've already made a similar change in some of our own json generation (unrelated to our services)
Comment #3
kehan commentedsubscribing
Comment #4
Steven Merrill commentedHey - look - a patch!
It's against CVS HEAD as of today. It will use json_encode if available, and GZIP compression if the client supports it. This helped boost performance quite a bit on BobDylan.com.
Enjoy!
Comment #5
karlsheaIt looks like this patch, or parts of it, made it into 2.0-alpha1?
There seems to be an issue with the gzip encoding part at the very end:
I see that there are lots of comments on the gzcompress page on php.net discussing removing the crc at the end, and string lengths, etc. But the result of these three lines are that this goes in:
{"#error":false,"#data":{"foo":"bar"}}and this comes out in the browser:
{"#error":false,"#data":{"foo":"barI double-checked this in Wireshark to make sure it wasn't just a browser issue, and it's getting cut off there after decompression as well.
If I remove the substring stuff and just send the gzcompress output to the browser, it gets uncompressed correctly in Firefox 3.6 on OS X at least. I'm not sure it's worth keeping in gzip compression if it's not going to work everywhere.
Comment #6
karlsheaI'm attaching a patch that seems to fix the issue, containing some code ported from some of the gzcompress manual page's comments. This adds the correct bytes for crc and size to the end of the gzipped string, and seems to fix the issue of characters being stripped from the end of the string.
Comment #7
evanbarter commented+1 for #6.
I noticed the malformed response in my browser but didn't think much of it. It wasn't until I started hitting the server in a mobile client I'm developing where it started causing all kinds of issues. Patch in #6 cleared these up.
Comment #8
jeffmace commentedIt looks like the problem is actually just because of the overhead of gzip on short strings. Some of the examples on the gzcompress page will only use gzcompress if the text is longer than 2048 characters. The attached patch does the same for json_server.module file and solved the issue for me without the overhead of more string concatenation.