Skip to content

Commit

Permalink
allow parsing empty json arrays and objects (netdata#19685)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsaou authored Feb 20, 2025
1 parent 5cf6732 commit 81de3f4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/collectors/log2journal/log2journal-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ static inline bool json_parse_array(LOG_JSON_STATE *js) {

size_t index = 0;
do {
const char *s = json_current_pos(js);
if(*s == ']') {
json_consume_char(js);
break;
}

if(!json_key_index_and_push(js, index))
return false;

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

const char *s = json_current_pos(js);
s = json_current_pos(js);
json_consume_char(js);
if(*s == ',') {
index++;
Expand All @@ -545,6 +551,12 @@ static inline bool json_parse_object(LOG_JSON_STATE *js) {
json_consume_char(js);

do {
const char *s = json_current_pos(js);
if(*s == '}') {
json_consume_char(js);
break;
}

if (!json_expect_char_after_white_space(js, "\""))
return false;

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

const char *s = json_current_pos(js);
s = json_current_pos(js);
json_consume_char(js);
if(*s == ',')
continue;
Expand Down

0 comments on commit 81de3f4

Please sign in to comment.