||2 months ago|
|include||2 months ago|
|Makefile||2 months ago|
|README.md||2 months ago|
|jsmnxpp_md_backup_test.cpp||2 months ago|
jsmnxpp - jsmn extended for c++
This is mini-header library that wraps and extends jsmn.h for c++ making it easier to use by providing that jsmn on its own doesn't:
- Type conversion via the
- String escape (e.g.
\u3242, etc.) translation when
- Easier access to nested members with
object key and array index lookups
At this time, this does not include a way to compose JSON, but neither does
I may make one in the future, but it would require adding more code from scratch, but
could be contained to a different header to manage the bloat so the main problem would
be the amount of debugging needed.
It appears to only run at half the speed of Rapidjson according to my current tests.
In my tests with using
jsmn.h in pure C, on the contrary I saw jsmn is capable of
running twice as fast as Rapidjson. So that means the overhead of my code is resulting
in performance that is a quarter of what
jsmn.h alone is capable of.
The cause appears to be the copies that occur when accessing members so a better solution may be needed.
Anyways, despite not living up to my performance expectations, it is still much faster than most JSON parsers and one advantage over Rapidjson in its reduced code size. So it may be an option for keeping your included code size under control.
The constructor parses the JSON string with
jsmn.h and makes it ready for use
If the current top level type is an object and the key exists within it a
only the value for that key is returned. Otherwise, exceptions are thrown.
If the top level is a JSON array and
index is within the size of the array, the
value at that index is returned. Otherwise, exceptions are thrown.
json object only contains a primitive value (not an array or object),
attempt to convert it to type T. If the conversion fails or if the
json is not
a primitive, exceptions will be thrown. For
std::string, translate escapes and
return the string.
Returns the number of elements or members in the top level of the JSON.
jsmnxpp::json j(json_str); std::cout << j["foo"]["bar"].get_as<std::string>() << std::endl; std::cout << j["some"]["number"].get_as<long>() << std::endl; for (size_t k = 0; k < j["some_list"].size(); k++) std::cout << j["some_list"][k].get_as<long>() << std::endl;