Enhancement for denoting "key" : value pairs

Issue #11 resolved
Anonymous created an issue

Hi ZSerge,

I have added a functionality to help make sure two tokens have a ':' between them by adding a "valueof" field to the token structure. In the token after the ':' the valueof will point to the token before the ':', and for all other tokens it will be -1 (in the same way a token will point to its parent when this is enabled).

.c file is attached, changes in .h are:
typedef struct {
jsmntype_t type;
int start;
int end;
int size;
int valueof;

ifdef JSMN_PARENT_LINKS

    int parent;

endif

} jsmntok_t;

/
* JSON parser. Contains an array of token blocks available. Also stores
* the string being parsed now and current position in that string
/
typedef struct {
unsigned int pos; /
offset in the JSON string /
int toknext; /
next token to allocate /
int toksuper; /
superior token node, e.g parent object or array /
int nextisval; /
flag: next token is value of previous */
} jsmn_parser;

Hope you find this useful!

Comments (5)

  1. Serge Zaitsev repo owner

    It's finally implemented! Now some string tokens have size of 1 which means they have a single child node. That's how you can tell key from a string value. It also simplifies parsing a lot. See commit 84cb5790d973

  2. Log in to comment