JSON 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.
You can't get much more 'opinion-less' than this library though. Iterate over keys and array items, identify the value type and return string-slices.
Sj.h: A tiny little JSON parsing library in ~150 lines of C99
21–30 of 248 posts
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#22on the more code side, love this, been looking to implement a simple json parser for some projects but this is small enough i can study it and either learn what i need or even use it. lovely!
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#23Earlier quoted context omitted.
You can't get much more 'opinion-less' than this library though. Iterate over keys and array items, identify the value type and return string-slices.
It also feels like only half the job to me. Reminds me of SAX "parsers" that were barely more than lexers.
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#24What’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
#25The library doesn’t check for signed integer overflow here: https://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
#26The library doesn’t check for signed integer overflow here: https://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.
Sometimes, it's just not the responsibility of the library. Trying to handle every possible errors is a quick way to complexity.
[0]: https://43081j.com/2025/09/bloat-of-edge-case-libraries
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#27this is really nice. i also _must_ use it because my initials are S.J H.. :'). on the more code side, love this, been looking to implement a simple json parser for some projects but this is small enough i can study it and either learn what i need or even use it. lovely!
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#28Earlier quoted context omitted.
It also feels like only half the job to me. Reminds me of SAX "parsers" that were barely more than lexers.
I mean, what else is there to do when iterating over a JSON file? Delegating number parsing and UNICODE handling to the user can be considered a feature (since I can decide on my own how expensive/robust I want this to be).
Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99
#29JSON 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
#30This is interesting, but how does this do on the conformance tests? https://github.com/nst/JSONTestSuite
What I mean by this is a subset (superset?) that exactly matches the parsing behavior of a specific target parsing library. Why is this useful? To avoid the class of vulnerabilities that rely on the same JSON being handled differently by two different parsers (you can exploit this to get around an authorization layer, for example).