61 lines
2.4 KiB
Plaintext
61 lines
2.4 KiB
Plaintext
### libjsonincpp
|
|
|
|
Suckless C++ library for storing JSON and generating and parsing JSON strings
|
|
|
|
### Examples
|
|
|
|
|
|
#include <libjsonincpp/jsonobj.h>
|
|
#include <libjsonincpp/string_representation.h>
|
|
|
|
void func(){
|
|
json::JSON obj = json::JSON("Hello, World\n");
|
|
assert(obj.isString());
|
|
std::cout << obj.asString() << std::endl;
|
|
}
|
|
|
|
void foo(){
|
|
json::JSON obj = json::JSON(std::vector<JSON>(JSON(12l), JSON(true)));
|
|
for (json::JSON& el: obj.asArray()){
|
|
std::cout << json::generate_str(el, json::print_pretty) << std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
### Pros
|
|
|
|
libjsonincpp is non-recurrsive, out-of-memory-safe C++ library.
|
|
|
|
Accessing a member of json object that does not exist (for example taking second element of true value, or taking element, corresponding to key "dict-key" of an array value)
|
|
does not result in error. libjsonincpp defines a special structure json::JSON_reference. It can be undefined. It is returned by operator[].
|
|
|
|
Also, this is a correct code in libjsonincpp:
|
|
|
|
|
|
json::JSON obj; // Initial value is null symbol
|
|
obj["aaaa"]["foo"][12][0] = JSON("value");
|
|
|
|
This code will automatically make obj a dictionary, make obj["aaaa"] a dictionary, make obj["aaaa"]["foo"] an array, e.t.c. And at the end, it will perform copy of "value"
|
|
|
|
### Cons
|
|
|
|
It has no cons, but more like "limitations":
|
|
|
|
JSON specification allows some crazy precise float values as JOSN number (imagine unironically handling float with decimal exponent equal to 99....999 with as
|
|
many nines as your internet connection can handle). Handling floats and big integers was not my goal. Thus, it can correctly interpret obly numbers with less then 19 digits.
|
|
Other number values are stored as unparsed strings.
|
|
|
|
Also, libregexis024 imposes a restriction on JSON string encoding: All JSON string values MUST be correct UTF-8 strings, otherwise generating string representation of
|
|
your JSON object will result in json::misuse exception.
|
|
|
|
### Dependencies
|
|
|
|
C++, regexis024_build_system
|
|
|
|
What is regexis024_build_system? It's nothing. Don't think about it. Just download it and forget about it.
|
|
|
|
Also, don't forget to disable overcommitment on your system in order for _your system_ to be usable.
|
|
Bruh, why don't we already rename OOM-killer to just regular killer and charge it for all the crimes it did?
|
|
Why we keep executing OOM-killer on our servers when we can take the guy who thought that overcommitment was a good idea and execute him on an electric chair?
|
|
|