summaryrefslogtreecommitdiff
path: root/json-glib/json-generator.c
diff options
context:
space:
mode:
authorEduardo Lima Mitev <elima@igalia.com>2011-01-27 16:58:48 +0100
committerEduardo Lima Mitev <elima@igalia.com>2011-03-11 16:01:20 +0100
commitaf70f34b3fc46a4c464418ebd6a16d9a1f18af8a (patch)
treed443d0d2c6a3e85de78d4c7450370c2e24adba99 /json-glib/json-generator.c
parent8bb22d7de00f15ef44cad502d757639d8a4e8973 (diff)
downloadjson-glib-af70f34b3fc46a4c464418ebd6a16d9a1f18af8a.tar.gz
generator: Removes blank spaces from generated JSON when not pretty-print
https://bugzilla.gnome.org/show_bug.cgi?id=640729
Diffstat (limited to 'json-glib/json-generator.c')
-rw-r--r--json-glib/json-generator.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c
index c3bdc9a..6a36bcf 100644
--- a/json-glib/json-generator.c
+++ b/json-glib/json-generator.c
@@ -293,7 +293,12 @@ dump_value (JsonGenerator *generator,
}
if (name && name[0] != '\0')
- g_string_append_printf (buffer, "\"%s\" : ", name);
+ {
+ if (pretty)
+ g_string_append_printf (buffer, "\"%s\" : ", name);
+ else
+ g_string_append_printf (buffer, "\"%s\":", name);
+ }
json_node_get_value (node, &value);
@@ -364,14 +369,17 @@ dump_array (JsonGenerator *generator,
}
if (name && name[0] != '\0')
- g_string_append_printf (buffer, "\"%s\" : ", name);
+ {
+ if (pretty)
+ g_string_append_printf (buffer, "\"%s\" : ", name);
+ else
+ g_string_append_printf (buffer, "\"%s\":", name);
+ }
g_string_append_c (buffer, '[');
if (pretty)
g_string_append_c (buffer, '\n');
- else
- g_string_append_c (buffer, ' ');
for (i = 0; i < array_len; i++)
{
@@ -415,8 +423,6 @@ dump_array (JsonGenerator *generator,
if (pretty)
g_string_append_c (buffer, '\n');
- else
- g_string_append_c (buffer, ' ');
}
if (pretty)
@@ -456,14 +462,17 @@ dump_object (JsonGenerator *generator,
}
if (name && name[0] != '\0')
- g_string_append_printf (buffer, "\"%s\" : ", name);
+ {
+ if (pretty)
+ g_string_append_printf (buffer, "\"%s\" : ", name);
+ else
+ g_string_append_printf (buffer, "\"%s\":", name);
+ }
g_string_append_c (buffer, '{');
if (pretty)
g_string_append_c (buffer, '\n');
- else
- g_string_append_c (buffer, ' ');
members = json_object_get_members (object);
@@ -482,8 +491,12 @@ dump_object (JsonGenerator *generator,
{
for (j = 0; j < (sub_level * indent); j++)
g_string_append_c (buffer, priv->indent_char);
+ g_string_append_printf (buffer, "\"%s\" : null", member_name);
+ }
+ else
+ {
+ g_string_append_printf (buffer, "\"%s\":null", member_name);
}
- g_string_append_printf (buffer, "\"%s\" : null", member_name);
break;
case JSON_NODE_VALUE:
@@ -512,8 +525,6 @@ dump_object (JsonGenerator *generator,
if (pretty)
g_string_append_c (buffer, '\n');
- else
- g_string_append_c (buffer, ' ');
}
g_list_free (members);