Live data from Hacker News

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

github.com

111–120 of 248 posts

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

#111
A recommendation: we use rxi's json.lua at Planimeter, but upon benchmarking JSON implementations across all major languages, it was found to be the slowest by an order of magnitude when reading very large numbers of JSON files.

So if you can, try and at least use LuaJIT, which when using json.lua seems to bring it back down into range with other performant languages, or jump down into LuaJIT and use Sj.h there, through the C FFI or just simdjson.

json.lua is great for when you're restricted in some ways to use a pure Lua implementation, though. It's the de facto solution.

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

#112

Earlier quoted context omitted.

The license says otherwise; hard to get freer than public domain.

Open source is a more informative term for this than free software. Not all free software is open source, but all open source software is free. Edit: I was not aware of the FSF's definition. I was using a definition of free software being software that you can use without having to pay for it.

> Not all free software is open sourc

Depends on which "free software" definition you're referring to.

The FSF definition of "free software" requires it to be open source.

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

#113

Earlier quoted context omitted.

The license says otherwise; hard to get freer than public domain.

Open source is a more informative term for this than free software. Not all free software is open source, but all open source software is free. Edit: I was not aware of the FSF's definition. I was using a definition of free software being software that you can use without having to pay for it.

I think you are mistaken; neither is a subset of the other. At the very least, there are licences which are recognised as open source by the OSI, but not as free by the FSF, and vice versa [1]. I think it’s more appropriate to say they are two fundamentally separate definitions with a massive overlap.

[1] https://spdx.org/licenses/

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

#114

A recommendation: we use rxi's json.lua at Planimeter, but upon benchmarking JSON implementations across all major languages, it was found to be the slowest by an order of magnitude when reading very large numbers of JSON files. So if you can, try and at least use LuaJIT, which when using json.lua seems to bring it back down into range with other performant languages, or jump down into LuaJIT and use Sj.h there, thro…

Other JSON libraries benchmarked here: https://github.com/andrewmcwattersandco/programming-language...

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

#115
post #8

What I love about this author's work is that they're usually single-file libraries in ANSI C or Lua with focused scope, easy-to-use interface, and good documentation. And free software license. Aside from the posted project, some I like are: - log.c - A simple logging library implemented in C99 - microui - A tiny immediate-mode UI library - fe - A tiny, embeddable language implemented in ANSI C - microtar - A lightwe…

It's open source, not free software.

"Source Available" and "Open Source" (with an OSI-approved license) are the terms you're looking for. "Free as in speech, or free as in beer?" is your rallying cry.

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

#116

Earlier quoted context omitted.

The license says otherwise; hard to get freer than public domain.

What is the stance of Your Average Corp’s security department on public domain software? Do they accept software under such licensing (or lack thereof)?

Who cares? Seriously. Whether a commercial entity who wants to be able to benefit from your work accepts the license you choose for work you do is as much a concern as whether or not the prime minister of Liechtenstein accepts the color you paint the outside of your house in the USA. That is: none.

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

#117

Earlier quoted context omitted.

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

There is no easy way out when you're working with C: either you handle all possible UB cases with exhaustive checks, or you move on to another language. (TIP: choose the latter)

For signed overflow you can just turn on the sanitizer in trapping mode. Exhaustive checks is also not that terrible.

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

#118
post #8

What I love about this author's work is that they're usually single-file libraries in ANSI C or Lua with focused scope, easy-to-use interface, and good documentation. And free software license. Aside from the posted project, some I like are: - log.c - A simple logging library implemented in C99 - microui - A tiny immediate-mode UI library - fe - A tiny, embeddable language implemented in ANSI C - microtar - A lightwe…

Oh yeah, I used their Lume library back when I did games in LOVE2D. I actually ran into them a couple times in the IRC chat (and told them one of their ideas was bad, sorry about that rxi, I checked and it's actually a good idea lol)

https://github.com/rxi/lume

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

#119

Earlier quoted context omitted.

2GB in a single JSON file is definitely an outlier. A simple caveat when using this header could suffice: ensure inputs are less than 2GB.

I've seen much bigger, though technically that wasn't valid json, but rather structured logging with JSON on each line. On the other hand, I've seen exported JSON files that could grow to such sizes without doing anything weird, just nothing exceeding a couple hundred megabytes because I didn't use the software for long enough. Restricting the input to a reasonable size is an easy workaround for sure, but this limita…

[deleted]

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

#120
post #116

Earlier quoted context omitted.

What is the stance of Your Average Corp’s security department on public domain software? Do they accept software under such licensing (or lack thereof)?

Who cares? Seriously. Whether a commercial entity who wants to be able to benefit from your work accepts the license you choose for work you do is as much a concern as whether or not the prime minister of Liechtenstein accepts the color you paint the outside of your house in the USA. That is: none.

Bad analogy.. if they truly care what colour your house is then there's plenty of strings they could pull. I mean, a good number of large U.S. company's tax and corporate structures depend heavily on Liechtenstein's government’s rules..
Post reply on HN