http://blog.llvm.org/2010/01/address-of-label-and-indirect-b...
A venerable interpreter implementation trick.
The C interface is purposely ugly but the C++ is much easier to work with.
I work a lot with very low-resource embedded systems and we like to use JSON host-side for structured data configuration, but convert to BSON (http://bsonspec.org) for target-side storage. This can be parsed and iterated with very low-overhead and no dynamic memory. Similar idea to protocol buffers but with JSON-like data.
Avoiding a build-time conversion would be nice, though, and this idea is interesting.
So it might be "malloc-free" for configuration files where the possible values are limited, etc. :)
jsmn is pretty awesome, and contrary to this (std::string, std::vector) actually puts you in charge of allocations. It's also in C.
In a similar vein, and also possibly already mentioned:
- yayl (C): https://lloyd.github.io/yajl/
- microjson (C): http://esr.ibiblio.org/?p=6262
I'm not sure how any JSON parser could avoid memory allocation without a difficult to use interface. Numbers, arrays, strings, and objects are unbounded by the JSON spec, so a truly malloc free library would need to provide a kind of streaming interfaces where things are returned in fixed sized chunks.
JSON wouldn't be my first choice for data storage in situations where I needed to avoid dynamic memory.