Skip to content

Commit 81de3f4

Browse files
authored
allow parsing empty json arrays and objects (netdata#19685)
1 parent 5cf6732 commit 81de3f4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/collectors/log2journal/log2journal-json.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,12 @@ static inline bool json_parse_array(LOG_JSON_STATE *js) {
513513

514514
size_t index = 0;
515515
do {
516+
const char *s = json_current_pos(js);
517+
if(*s == ']') {
518+
json_consume_char(js);
519+
break;
520+
}
521+
516522
if(!json_key_index_and_push(js, index))
517523
return false;
518524

@@ -524,7 +530,7 @@ static inline bool json_parse_array(LOG_JSON_STATE *js) {
524530
if(!json_expect_char_after_white_space(js, ",]"))
525531
return false;
526532

527-
const char *s = json_current_pos(js);
533+
s = json_current_pos(js);
528534
json_consume_char(js);
529535
if(*s == ',') {
530536
index++;
@@ -545,6 +551,12 @@ static inline bool json_parse_object(LOG_JSON_STATE *js) {
545551
json_consume_char(js);
546552

547553
do {
554+
const char *s = json_current_pos(js);
555+
if(*s == '}') {
556+
json_consume_char(js);
557+
break;
558+
}
559+
548560
if (!json_expect_char_after_white_space(js, "\""))
549561
return false;
550562

@@ -564,7 +576,7 @@ static inline bool json_parse_object(LOG_JSON_STATE *js) {
564576
if(!json_expect_char_after_white_space(js, ",}"))
565577
return false;
566578

567-
const char *s = json_current_pos(js);
579+
s = json_current_pos(js);
568580
json_consume_char(js);
569581
if(*s == ',')
570582
continue;

0 commit comments

Comments
 (0)