Live data from Hacker News

Sj.h: A tiny little JSON parsing library in ~150 lines of C99

github.com

21–30 of 248 posts

Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99

#21
post #12

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.

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

#22
this 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

#23

Earlier 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.

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

#25
post #19

The 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.

Submit a PR!

Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99

#26
post #19

The 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.

There was a nice article [0] about bloated edge cases libraries (discussion [1]).

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

[1]: https://news.ycombinator.com/item?id=45319399

Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99

#27
post #22

this 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!

[dead]

Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99

#28

Earlier 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).

That is what I like Common Lisp libraries. They are mostly about the algorithms, leaving data structures up to the user. So you make sure you got those rights before calling the function.

Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99

#29
post #12

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.

The project advertises that it has zero-allocations with minimal state. I don’t think it is fair or our problems are very different. Single string, (the most used type), and you need an allocation.

Re: Sj.h: A tiny little JSON parsing library in ~150 lines of C99

#30
post #2

This is interesting, but how does this do on the conformance tests? https://github.com/nst/JSONTestSuite

You know what would really be useful is a conformance test based on a particular real implementation.

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).

Post reply on HN