CJSON – Ultralightweight JSON parser in ANSI C
github.com
github.com
I have an aversion to learning it because it seems like an abstraction of an abstraction and of little value. But I’d like to change my mind.
(Thanks for this btw, I was looking for something like this)
One of the things I've never been a fan of is that for whatever reason, the build steps that you see in basically every project are: - mkdir ./build - cd ./build - cmake configure ../ - make build
Has no one thought of simplifying that??
Not sure people "like" it, but they claim it makes the job easier.
Sometimes cmake is optional. That is, one can still type "make" on Linux/BSD and just ignore the cmake files. Unfortunately, that seems to be the less common way to use cmake.
Using cmake on Linux/BSD does seem like overkill. It is not necessary. I share the aversion to learning cmake but always figured complaining about it would not be well-received.
Now what I don’t get is why Meson is so popular. I haven’t dived into it, but from the outside it doesn’t look like all that different from CMake. Seems to me like the vast majority of Meson projects would be better off with CMake just because it’s more mature and well known, but otherwise does the exact same thing.
Meson is the next runner up and it should come with a religious text about how the creator thinks software should work.
- is easily boostrappable
- works on OS without any kind of POSIX shell
- allow to extract, download, create file / directories in a cross-platform way (cmake extracts 7z, zip, .tar.gz and friends on every platform with a single command)
- allow to quickly parse and generate code with regexps without having to fight with whatever difference between versions of perl, rename, etc. there are on the host system
- does not require "quoting" every flag or source file (seriously, this is just a pain in most more recent BS)
- just works with everything that can be thrown at it and accommodates the project's way of handling dependencies instead of trying to impose its own
- easily allows to find dependencies on systems with no canonical path to look for them
1. It's widely available (even on Windows). 2. It's not as bad as autotools.
> You can have perfectly readable code in a single file that is 1000s loc.
You can if you are dealing with a single concept. JSON parsing is not a single concept. You can easily split that up into more understandable modules. In fact I would wager that any JSON library that has not modularised serialization, deserialization and object building/modification into modules is not doing a good job.
It's not like more c files cost anything. It's not comparable to header-only libs since they will compile to an object file anyway.
I am developing an Apache module that does some authentication stuff, and I needed a way to parse and read JSON in C. I really did not want to deal with doing that myself, and I wanted to avoid any complicated library.
This is super easy to use, and is just one file.
Are you parsing JWT objects?
A parser written in C shouldn’t be used on something like an authentication library for web services.
Whether or not it makes sense to do it like that is another story, but I don't have control over the design of enterprise architecture.
This creates json, can emit json structurally, and parses json. You don't really need to emit json, printf in some macros is usually enough.
This parser is heavy, creating copies.
But it's much easier to use than jsmn. jsmn needs two loops and special handling of the various types. There's no high-level API to get the values of an array nested in an object. CJson has it, at the cost of copies and 2x memory and slowness.