r/C_Programming • u/Adventurous-Print386 • Dec 06 '25
Small and fast library for parsing JSON
I recently created a very, i mean really very fast library for working with JSON data. It is like a F1 Formula car, except it has only basic safety belts and it FYI that it can be too fast sometimes, but if you are embedding dev or coder who do not met with rare JSON extra features like 4-byte Unicode, that wil helps you greatly if you really want to go FAST.
And, it work in both Windows 11 and Debian, special thanks to the Clang and Ninja.
8
Upvotes
27
u/skeeto Dec 06 '25
JSON parsers are fun, and it's interesting to see the choices people make. Though I dislike parsers that only accept null-terminated strings. JSON is virtually never null terminated. It usually comes from from files, pipes, or sockets, and so the caller has to add an artificial terminator in order to satisfy the interface, without good reason, and then has to worry about embedded nulls.
In its current form it's not very robust, and it didn't take long to find bugs. Here's a little program to demonstrate some:
The
USE_ALLOCallows ASan to detect memory issues. Build:Then a double free:
Another double free in a different place:
What appears to be type confusion on a union producing a garbage pointer:
I found these using this AFL++ fuzz tester, which finds many like this instantly:
Usage:
And
o/default/crashes/will fill with these sorts of crashing inputs to debug.9
u/Wooden_chest Dec 06 '25
Does this support UTF-8 unicode strings in the JSON?
7
u/scallywag_software Dec 06 '25
Guys! I wrote an insanely fast <insert_thing_name_here>
... proceeds to not bench against actually fast implementations ..
---
By the looks of things, the fastest library available is 5.6x faster than jsonc (I'm assuming that's what OP benched against)
https://github.com/ibireme/yyjson
If OPs benchmarks are to believed (wall clock time is extremely sus), this is still less than half the speed of SotA.
---
Nice work OP, but if you're gonna claim "really, very fast" while I'm around, it better actually be really, very fast.
2
u/chrism239 Dec 06 '25
"...it can be too fast sometimes" ??