parser json BUGFIX finish anydata parsing

Fixes #1783
diff --git a/src/parser_json.c b/src/parser_json.c
index e88f4c0..eb62897 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1187,7 +1187,6 @@
                 LY_CHECK_RET(lyjson_ctx_next(lydctx->jsonctx, status));
                 assert(*status == LYJSON_ARRAY_CLOSED);
             }
-            LY_CHECK_RET(lyjson_ctx_next(lydctx->jsonctx, status));
         } else if (snode->nodetype == LYS_ANYXML) {
             LY_CHECK_RET((*status != LYJSON_STRING) && (*status != LYJSON_NULL), LY_EINVAL);
 
@@ -1208,9 +1207,6 @@
                     return ret;
                 }
             }
-
-            /* move JSON parser */
-            LY_CHECK_RET(lyjson_ctx_next(lydctx->jsonctx, status));
         } else if (snode->nodetype & LYD_NODE_INNER) {
             /* create inner node */
             LY_CHECK_RET((*status != LYJSON_OBJECT) && (*status != LYJSON_OBJECT_EMPTY), LY_EINVAL);
@@ -1249,10 +1245,6 @@
             }
 
             LOG_LOCBACK(1, 1, 0, 0);
-
-            /* move JSON parser */
-            ret = lyjson_ctx_next(lydctx->jsonctx, status);
-            LY_CHECK_RET(ret);
         } else if (snode->nodetype == LYS_ANYDATA) {
             /* create any node */
             LY_CHECK_RET((*status != LYJSON_OBJECT) && (*status != LYJSON_OBJECT_EMPTY), LY_EINVAL);
@@ -1284,6 +1276,9 @@
             LY_CHECK_RET(ret);
         }
 
+        /* move JSON parser */
+        LY_CHECK_RET(lyjson_ctx_next(lydctx->jsonctx, status));
+
         /* add/correct flags */
         lyd_parse_set_data_flags(*node, &lydctx->node_when, &lydctx->node_exts, &(*node)->meta, lydctx->parse_opts);
     } else if (ret == LY_ENOT) {
diff --git a/tests/utests/data/test_parser_json.c b/tests/utests/data/test_parser_json.c
index 92cbe2c..e9fb705 100644
--- a/tests/utests/data/test_parser_json.c
+++ b/tests/utests/data/test_parser_json.c
@@ -250,6 +250,15 @@
             1, LYS_ANYDATA, 0, 0, NULL, 0);
     CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
     lyd_free_all(tree);
+
+    data = "{\"a:any\":{}}";
+    CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree);
+    assert_non_null(tree);
+    tree = tree->next;
+    CHECK_LYSC_NODE(tree->schema, NULL, 0, LYS_SET_ENUM | LYS_CONFIG_R | LYS_YIN_ARGUMENT, 1, "any",
+            1, LYS_ANYDATA, 0, 0, NULL, 0);
+    CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
+    lyd_free_all(tree);
 }
 
 static void