After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 640729 - Unnecessary blank spaces in generated JSON even with pretty-print disabled
Unnecessary blank spaces in generated JSON even with pretty-print disabled
Status: RESOLVED FIXED
Product: json-glib
Classification: Core
Component: Generator
git master
Other Linux
: Normal normal
: ---
Assigned To: json-glib-maint
json-glib-maint
Depends on:
Blocks:
 
 
Reported: 2011-01-27 15:22 UTC by Eduardo Lima Mitev
Modified: 2012-03-13 22:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to fix it (13.83 KB, patch)
2011-01-27 16:10 UTC, Eduardo Lima Mitev
accepted-commit_now Details | Review

Description Eduardo Lima Mitev 2011-01-27 15:22:23 UTC
The generator always produces JSON with blank spaces to separate some data tokens, even when "pretty" property is false. e.g:

"[ 1, 2, 3 ]" -> 4 blank spaces
"[ {"foo" : null}, {"bar" : null} ]" -> 7 blank spaces

This is unnecessary if there is already a "pretty" version with proper indentation and spacing, intended to be easily readable by humans. These blanks are undesirable when JSON is to be consumed by a computer, like for example when used to build protocols or any case where JSON is put on a wire.

Bug is about removing these blank spaces in generated JSON, when "pretty" property is disabled.
Comment 1 Eduardo Lima Mitev 2011-01-27 16:10:18 UTC
Created attachment 179440 [details] [review]
patch to fix it

This patch shall fix this. Affected tests were updated.

In some test cases that were updated, it is very noticeable how much the length of the JSON string is reduced, just by stripping the unnecessary blanks.
Comment 2 Eduardo Lima Mitev 2011-03-10 18:13:59 UTC
Any comment on this? In my use case I have to move generated JSON over a network connection and I'm losing precious bandwidth with those blanks :(.

Any chance to have this at least discussed?

cheers
Comment 3 Emmanuele Bassi (:ebassi) 2011-03-11 13:59:04 UTC
Review of attachment 179440 [details] [review]:

I'm not entirely convinced that a bunch of spaces are going to have that big of an impact on bandwidth; if you're really sending/receiving that amount of data, I'd suggest using a compression module on the web server, and passing through an InputStream to uncompress the data.

on the other hand, I don't have that much of an issue with the patch in and of itself, except that it makes debugging slightly more difficult.

anyway, feel free to commit to master.
Comment 4 Eduardo Lima Mitev 2011-03-11 15:16:09 UTC
(In reply to comment #3)
> Review of attachment 179440 [details] [review]:
> 
> I'm not entirely convinced that a bunch of spaces are going to have that big of
> an impact on bandwidth; if you're really sending/receiving that amount of data,
> I'd suggest using a compression module on the web server, and passing through
> an InputStream to uncompress the data.

Well, it depends on the amount of that to be moved. For small JSON messages probably the HTTP headers or other transport overheads make this unworthy, but as the length of the message increases, the penalty is noticed. Compression does help, but at the cost of performance.

My rationale is that having the blanks is unnecessarily suboptimal.

> anyway, feel free to commit to master.

Pushed to master, thanks.
Comment 5 André Klapper 2012-03-13 22:08:24 UTC
[Fixing Default QA assignee for json-glib - see 613232#c1. Sorry for bugmail noise.]