From 428ad5fa685cefb1af311686c6f3ac0b04111a64 Mon Sep 17 00:00:00 2001 From: "Serge A. Zaitsev" Date: Sat, 30 Mar 2019 21:23:13 +0100 Subject: [PATCH] add changes from PR #142 --- example/jsondump.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/example/jsondump.c b/example/jsondump.c index d7217bd..1eb6206 100644 --- a/example/jsondump.c +++ b/example/jsondump.c @@ -27,6 +27,7 @@ static inline void *realloc_it(void *ptrmem, size_t size) { static int dump(const char *js, jsmntok_t *t, size_t count, int indent) { int i, j, k; + jsmntok_t *key; if (count == 0) { return 0; } @@ -40,11 +41,15 @@ static int dump(const char *js, jsmntok_t *t, size_t count, int indent) { printf("\n"); j = 0; for (i = 0; i < t->size; i++) { - for (k = 0; k < indent; k++) + for (k = 0; k < indent; k++) { printf(" "); - j += dump(js, t + 1 + j, count - j, indent + 1); - printf(": "); - j += dump(js, t + 1 + j, count - j, indent + 1); + } + key = t + 1 + j; + j += dump(js, key, count - j, indent + 1); + if (key->size > 0) { + printf(": "); + j += dump(js, t + 1 + j, count - j, indent + 1); + } printf("\n"); } return j + 1; @@ -52,8 +57,9 @@ static int dump(const char *js, jsmntok_t *t, size_t count, int indent) { j = 0; printf("\n"); for (i = 0; i < t->size; i++) { - for (k = 0; k < indent - 1; k++) + for (k = 0; k < indent - 1; k++) { printf(" "); + } printf(" - "); j += dump(js, t + 1 + j, count - j, indent + 1); printf("\n");