zserge / jsmn

Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
MIT License
3.64k stars 778 forks source link

How should we do to deal with unknown size of jsmn_tokens? #201

Closed littlesonlp closed 3 years ago

littlesonlp commented 3 years ago

For example, my json file could be very small, it also could be very big. How should I define the jsmn_token array? is there any version that use something like linked list instead of a fix size of array?

pt300 commented 3 years ago

If you are dealing with JSON that varies in size greatly, you can reallocate the tokens array based on feedback from the parser. If parser returns JSMN_ERROR_NOMEM you can extend the tokens array and retry parsing. The parser will continue from where it left off.

wshclth commented 3 years ago

Passing NULL instead of tokens will return the number of tokens needed.