diff --git a/mio/bin/t03.c b/mio/bin/t03.c index 5b5ca5d..c16a27e 100644 --- a/mio/bin/t03.c +++ b/mio/bin/t03.c @@ -120,6 +120,7 @@ int main (int argc, char* argv[]) for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--permit-word-key") == 0) o |= MIO_JSON_PERMIT_WORD_KEY; + if (strcmp(argv[i], "--optional-comma") == 0) o |= MIO_JSON_OPTIONAL_COMMA; } mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL); diff --git a/mio/lib/json.c b/mio/lib/json.c index b3b5dd4..db19440 100644 --- a/mio/lib/json.c +++ b/mio/lib/json.c @@ -503,8 +503,15 @@ static int handle_char_in_array (mio_json_t* json, mio_ooci_t c) { if (json->state_stack->u.ia.got_value) { - mio_seterrbfmt (json->mio, MIO_EINVAL, "comma required in array - %jc", (mio_ooch_t)c); - return -1; + if (json->option & MIO_JSON_OPTIONAL_COMMA) + { + json->state_stack->u.ia.got_value = 0; + } + else + { + mio_seterrbfmt (json->mio, MIO_EINVAL, "comma required in array - %jc", (mio_ooch_t)c); + return -1; + } } if (c == '\"') @@ -589,8 +596,14 @@ static int handle_char_in_object (mio_json_t* json, mio_ooci_t c) } else if (json->state_stack->u.io.state == 3) { - mio_seterrbfmt (json->mio, MIO_EINVAL, "comma required in object - %jc", (mio_ooch_t)c); - return -1; + if (json->option & MIO_JSON_OPTIONAL_COMMA) + { + json->state_stack->u.io.state = 0; + } + else + { + mio_seterrbfmt (json->mio, MIO_EINVAL, "comma required in object - %jc", (mio_ooch_t)c); + } } if (c == '\"')