Earlier quoted context omitted.
Real question, does it manage nested objects ?
It seems so: https://github.com/rxi/sj.h/blob/master/demo%2Fobject.c
Sj.h: A tiny little JSON parsing library in ~150 lines of C99
11–20 of 248 posts
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#12They're either written with a different use case in mind, or a complex mess of abstractions; often both.
It's not a very difficult problem to solve if you only write exactly what you need for your specific use case.
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#13What’s the usecase for something like this? There are lots of excellent libraries for json available. Is this a teaching tool?
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#14Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#15What’s the usecase for something like this? There are lots of excellent libraries for json available. Is this a teaching tool?
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#16Earlier quoted context omitted.
It seems so: https://github.com/rxi/sj.h/blob/master/demo%2Fobject.c
yep but how deep can you parse nested into nested etc
The nesting is limited by using an int as the depth counter. The C standard guarantees that MAX_INT is at least 32767, so that’s a limit on portable nesting depth. Nowadays int is typically 32 or 64 bits, so a much higher limit in typical C implementations.
If I see correctly, the library doesn’t check for overflow, however. This might conceivably be an exploitable vulnerability (and such an overflow would constitute UB).
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#17JSON parser libraries in general is a black hole of suffering imo. They're either written with a different use case in mind, or a complex mess of abstractions; often both. It's not a very difficult problem to solve if you only write exactly what you need for your specific use case.
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#18What’s the usecase for something like this? There are lots of excellent libraries for json available. Is this a teaching tool?
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#19https://github.com/rxi/sj.h/blob/eb725e0858877e86932128836c1...
https://github.com/rxi/sj.h/blob/eb725e0858877e86932128836c1...
https://github.com/rxi/sj.h/blob/eb725e0858877e86932128836c1...
Certain inputs can therefore trigger UB.
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#20I can see one bug just glancing at the code - feeding a stray '}' at the top level can result in depth becoming negative
https://github.com/rxi/sj.h/blob/eb725e0858877e86932128836c1...