-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I know if a token is a member name (key) or a value? #163
Comments
Oops, the fourth chunk above is obviously wrong. It should have been: @@ -374,8 +377,20 @@
case ' ':
break;
case ':':
+ {
+#ifdef JSMN_STRICT
+ /* In strict mode members names are strings */
+ if (tokens)
+ {
+ jsmntok_t *key = parser->toknext >= 1? &tokens[parser->toknext - 1]: NULL;
+ if (key == NULL || key->type != JSMN_STRING)
+ return JSMN_ERROR_INVAL;
+ key->is_key = 1;
+ }
+#endif
parser->toksuper = parser->toknext - 1;
break;
+ }
case ',':
if (tokens != NULL && parser->toksuper != -1 &&
tokens[parser->toksuper].type != JSMN_ARRAY && |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The colon terminal ('
:
') seems to exist just for that, so it can be flagged while parsing. Doing it later requires careful counting (as in jsondump). Storingis_key
requires just one bit of the token type:The third hunk (
int
instead ofjsmntype_t
) is not related to this bug. It just avoids a compiler warning, which appeared also before changing the definition ofjsmntok_t
. See this question at stackoverflow.After the change, existing tests work fine. In addition, I tried this:
That way, jsondump aborts if it's not compiled with
JSMN_STRICT
. Otherwise it works. I should also check that no token is markedis_key
if it's not. Oh, well...I found an old bug #23. The change envisaged there would not be backward compatible. The code mentioned there is not available. The intent, however, is similar.
The text was updated successfully, but these errors were encountered: