diff --git a/mongoose.c b/mongoose.c index e6528c37..06cec604 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2532,6 +2532,7 @@ int mg_json_get(struct mg_str json, const char *path, int *toklen) { } else if (c == '}') { // Empty object MG_EOO('}'); expecting = S_COMMA_OR_EOO; + if (depth == ed && ei >= 0) ci++; } else { return MG_JSON_INVALID; } diff --git a/src/json.c b/src/json.c index e41d4b27..b97f8c49 100644 --- a/src/json.c +++ b/src/json.c @@ -182,6 +182,7 @@ int mg_json_get(struct mg_str json, const char *path, int *toklen) { } else if (c == '}') { // Empty object MG_EOO('}'); expecting = S_COMMA_OR_EOO; + if (depth == ed && ei >= 0) ci++; } else { return MG_JSON_INVALID; } diff --git a/test/unit_test.c b/test/unit_test.c index e0a9cd91..39fdb874 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -2792,6 +2792,10 @@ static void test_json(void) { json = mg_str("{\"a\":1,\"b\":[1,2]}"); ASSERT(mg_json_get(json, "$.a", &n) == 5 && n == 1); ASSERT(mg_json_get(json, "$.a[0]", &n) < 0 && n == 0); + + ASSERT(mg_json_get_long(mg_str("[0, 42]"), "$[1]", 0) == 42); + ASSERT(mg_json_get_long(mg_str("[[], 42]"), "$[1]", 0) == 42); + ASSERT(mg_json_get_long(mg_str("[{}, 42]"), "$[1]", 0) == 42); } static void resp_rpc(struct mg_rpc_req *r) {