diff --git a/src/parser_json.c b/src/parser_json.c index 6facc07ab..d7f2fa57d 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -1491,11 +1491,11 @@ lydjson_parse_instance(struct lyd_json_ctx *lydctx, struct lyd_node *parent, str r = lydjson_data_check_opaq(lydctx, snode, &type_hints); if (r == LY_SUCCESS) { assert(snode->nodetype & (LYD_NODE_TERM | LYD_NODE_INNER | LYD_NODE_ANY)); - if (snode->nodetype & LYD_NODE_TERM) { - if ((lydctx->parse_opts & LYD_PARSE_JSON_NULL) && (*status == LYJSON_NULL)) { - /* do not do anything if value is JSON 'null' */ - goto cleanup; - } else if ((*status != LYJSON_ARRAY) && (*status != LYJSON_NUMBER) && (*status != LYJSON_STRING) && + if ((lydctx->parse_opts & LYD_PARSE_JSON_NULL) && (*status == LYJSON_NULL)) { + /* do not do anything if value is JSON 'null' */ + goto cleanup; + } else if (snode->nodetype & LYD_NODE_TERM) { + if ((*status != LYJSON_ARRAY) && (*status != LYJSON_NUMBER) && (*status != LYJSON_STRING) && (*status != LYJSON_FALSE) && (*status != LYJSON_TRUE) && (*status != LYJSON_NULL)) { rc = LY_ENOT; goto cleanup; @@ -1522,10 +1522,6 @@ lydjson_parse_instance(struct lyd_json_ctx *lydctx, struct lyd_node *parent, str r = lydjson_parse_instance_inner(lydctx, snode, ext, status, node); LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup); } else { - if ((lydctx->parse_opts & LYD_PARSE_JSON_NULL) && (*status == LYJSON_NULL)) { - /* do not do anything if value is JSON 'null' */ - goto cleanup; - } /* create any node */ r = lydjson_parse_any(lydctx, snode, ext, status, node); LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup); diff --git a/tests/utests/data/test_parser_json.c b/tests/utests/data/test_parser_json.c index f7311617f..1eff7819a 100644 --- a/tests/utests/data/test_parser_json.c +++ b/tests/utests/data/test_parser_json.c @@ -508,6 +508,11 @@ test_container(void **state) CHECK_PARSE_LYD("{\"a:unknown\":{\"a\":\"val\",\"b\":5}}", 0, LYD_VALIDATE_PRESENT, tree); CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, "{}"); lyd_free_all(tree); + + data = "{\"a:c\": null}"; + PARSER_CHECK_ERROR(data, 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, "Expecting JSON name/object but container \"c\" is represented in input data as name/null.", NULL, 1); + CHECK_PARSE_LYD(data, LYD_PARSE_JSON_NULL, LYD_VALIDATE_PRESENT, tree); + assert_null(tree); } static void