diff --git a/src/core/store_json.c b/src/core/store_json.c
index d9fc37c4b30d498b3340fce1b238b177f57ad95d..b4b7b6a8af4b1becfb02431e43188325355f29b4 100644 (file)
--- a/src/core/store_json.c
+++ b/src/core/store_json.c
* the path pointing to the current object */
int context[8];
size_t current;
+
+ int flags;
};
/*
*/
sdb_store_json_formatter_t *
-sdb_store_json_formatter(sdb_strbuf_t *buf)
+sdb_store_json_formatter(sdb_strbuf_t *buf, int flags)
{
sdb_store_json_formatter_t *f;
f->buf = buf;
f->context[0] = 0;
f->current = 0;
+ f->flags = flags;
return f;
} /* sdb_store_json_formatter */
/* first host */
if (! f->context[0]) {
+ if (f->flags & SDB_WANT_ARRAY)
+ sdb_strbuf_append(f->buf, "[");
assert(f->current == 0);
f->context[0] = SDB_HOST;
return json_emit(f, obj);
if (! f)
return -1;
+ if (! f->context[0]) {
+ /* no content */
+ if (f->flags & SDB_WANT_ARRAY)
+ sdb_strbuf_append(f->buf, "[]");
+ return 0;
+ }
+
while (f->current > 0) {
sdb_strbuf_append(f->buf, "}]");
--f->current;
}
- if (f->context[0])
- sdb_strbuf_append(f->buf, "}");
+
+ sdb_strbuf_append(f->buf, "}");
+ if (f->flags & SDB_WANT_ARRAY)
+ sdb_strbuf_append(f->buf, "]");
return 0;
} /* sdb_store_json_finish */