jsmn_parse requires extra loop over tokens array to know number of tokens have been extracted

Issue #16 resolved
Anonymous created an issue

It looks there is no quick way to know how many tokens have been pushed into "jsmntok_t *tokens" param of jsmn_parse method.

To understand how many tokens have been extracted user should make an extra iteration over tokens array. The extra iteration should be done before calling jsmn_parse method. It is necessary to init jsmntype_t member of every tokens array member by an invalid value (-1 for example). Once jsmn_parse returns JSMN_SUCCESS the invalid value of jsmntype_t member can be used to ensure end of extracted data reached.

Comments (2)

  1. Artour Bakiev

    Hi, Serge,

    I would like to update the issue. It looks like the issue concerns non strict mode only when there is no "root" object/array exists. For strict mode JSON requires "root" object so we always use jsmntok_t.size to find out last element in tokens array.

    Could you please decrease the priority.

  2. Log in to comment