json BUGFIX proper array parse and print
Includes the special [null] array and
any lists (array of objects) and
leaf-lists (array of values).
Refs cesnet/libnetconf2#331
diff --git a/src/printer_json.c b/src/printer_json.c
index dea32d3..0682309 100644
--- a/src/printer_json.c
+++ b/src/printer_json.c
@@ -601,12 +601,13 @@
has_content = 1;
}
- if (!node->schema || (node->schema->nodetype != LYS_LIST)) {
+ if ((node->schema && (node->schema->nodetype == LYS_LIST)) ||
+ (!node->schema && (((struct lyd_node_opaq *)node)->hints & LYD_NODEHINT_LIST))) {
+ ly_print_(ctx->out, "%s%*s{%s", (is_open_array(ctx, node) && ctx->level_printed >= ctx->level) ?
+ (DO_FORMAT ? ",\n" : ",") : "", INDENT, (DO_FORMAT && has_content) ? "\n" : "");
+ } else {
ly_print_(ctx->out, "%s{%s", (is_open_array(ctx, node) && ctx->level_printed >= ctx->level) ? "," : "",
(DO_FORMAT && has_content) ? "\n" : "");
- } else {
- ly_print_(ctx->out, "%s%*s{%s", (is_open_array(ctx, node) && ctx->level_printed >= ctx->level) ? (DO_FORMAT ? ",\n" : ",") : "",
- INDENT, (DO_FORMAT && has_content) ? "\n" : "");
}
LEVEL_INC;
@@ -772,10 +773,14 @@
if (node->hints & (LYD_NODEHINT_LIST | LYD_NODEHINT_LEAFLIST)) {
LY_CHECK_RET(json_print_array_open(ctx, &node->node));
- LEVEL_INC;
}
+ if (node->hints & LYD_NODEHINT_LEAFLIST) {
+ ly_print_(ctx->out, "%*s", INDENT);
+ }
+ } else if (node->hints & LYD_NODEHINT_LEAFLIST) {
+ ly_print_(ctx->out, ",%s%*s", DO_FORMAT ? "\n" : "", INDENT);
}
- if (node->child || (node->hints & (LYD_NODEHINT_LIST | LYD_NODEHINT_LEAFLIST))) {
+ if (node->child || (node->hints & LYD_NODEHINT_LIST)) {
LY_CHECK_RET(json_print_inner(ctx, &node->node));
LEVEL_PRINTED;
} else {
@@ -795,7 +800,6 @@
}
if (last && (node->hints & (LYD_NODEHINT_LIST | LYD_NODEHINT_LEAFLIST))) {
json_print_array_close(ctx);
- LEVEL_DEC;
LEVEL_PRINTED;
}