allow primitive and string type on its own (without object or array) - json2tsv - JSON to TSV converter
(HTM) git clone git://git.codemadness.org/json2tsv
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit d58761df609fb30dce860560b849f7f2d389e007
(DIR) parent 38d0984744efb248bfe773431d922a63cd09e0e3
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
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(-)
---
(DIR) diff --git a/json2tsv.c b/json2tsv.c
@@ -123,6 +123,7 @@ parsejson(void (*cb)(struct json_node *, size_t, const char *), const char **err
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 char *), const char **err
*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;