allow primitive and string type on its own (without object or array) - json2tsv… | |
git clone git://git.codemadness.org/json2tsv | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit d58761df609fb30dce860560b849f7f2d389e007 | |
parent 38d0984744efb248bfe773431d922a63cd09e0e3 | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Tue, 15 Oct 2019 18:53:51 +0200 | |
allow primitive and string type on its own (without object or array) | |
now valid: | |
1 | |
true | |
null | |
"string" | |
Diffstat: | |
M json2tsv.c | 7 +++++++ | |
1 file changed, 7 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/json2tsv.c b/json2tsv.c | |
@@ -123,6 +123,7 @@ parsejson(void (*cb)(struct json_node *, size_t, const char… | |
if (capacity(&(nodes[0].name), &(nodes[0].namesiz), 0, 1) == -1) | |
goto end; | |
nodes[0].name[0] = '\0'; | |
+ nodes[depth].type = TYPE_PRIMITIVE; | |
while ((c = GETNEXT()) != EOF) { | |
/* not whitespace or control-character */ | |
@@ -274,6 +275,12 @@ parsejson(void (*cb)(struct json_node *, size_t, const cha… | |
*errstr = JSON_ERROR_BALANCE; | |
goto end; | |
} | |
+ if (v || nodes[depth].type == TYPE_STRING) { | |
+ if (capacity(&value, &vz, v, 1) == -1) | |
+ goto end; | |
+ value[v] = '\0'; | |
+ cb(nodes, depth + 1, value); | |
+ } | |
ret = 0; /* success */ | |
*errstr = NULL; |