]> mj.ucw.cz Git - libucw.git/blobdiff - ucw-json/format.c
JSON: More tests and bug fixes
[libucw.git] / ucw-json / format.c
index 58526c84b2c470493bffda0d86818dd2742cc7a9..30f8757fd799199ad0c47ffd6c99c0de1018768d 100644 (file)
@@ -134,21 +134,24 @@ void json_write_value(struct json_context *js, struct json_node *n)
       {
        if (!GARY_SIZE(n->pairs))
          bputs(fb, "{}");
-       bputc(fb, '{');
-       js->out_indent++;
-       for (size_t i=0; i < GARY_SIZE(n->pairs); i++)
+       else
          {
-           if (i)
-             bputc(fb, ',');
+           bputc(fb, '{');
+           js->out_indent++;
+           for (size_t i=0; i < GARY_SIZE(n->pairs); i++)
+             {
+               if (i)
+                 bputc(fb, ',');
+               write_space(js);
+               struct json_pair *p = &n->pairs[i];
+               write_string(js, p->key);
+               bputs(fb, ": ");
+               json_write_value(js, p->value);
+             }
+           js->out_indent--;
            write_space(js);
-           struct json_pair *p = &n->pairs[i];
-           write_string(js, p->key);
-           bputs(fb, ": ");
-           json_write_value(js, p->value);
+           bputc(fb, '}');
          }
-       js->out_indent--;
-       write_space(js);
-       bputc(fb, '}');
        break;
       }
     default: