jsonpp is a header-only JSON parser and writer that is currently in development. It is a semi-strict parser that throws exceptions for errors.
jsonpp is licensed with the MIT license.
- Easy to use with a simple API.
- No special null, array, or object types.
json::null
is a type alias tostd::nullptr_t
.json::array
isstd::vector<json::value>
.json::object
isstd::map<std::string, json::value>
.
- Decently fast.
- No dependencies, only the standard library and a C++11 compiler.
Documentation is an on going process and can be found here. Amongst documentation you can also find examples.
#include <jsonpp/parser.hpp>
#include <iostream>
int main() {
json::parser p;
json::value v;
try {
p.parse("[null, \"hello\", 10.0]", v);
if(v.is<json::array>()) {
for(auto&& val : v.as<json::array>()) {
std::cout << val.as<std::string>("stuff");
}
}
}
catch(const std::exception& e) {
std::cerr << e.what() << '\n';
}
}
Output:
stuff hello stuff
#include <jsonpp/value.hpp>
#include <iostream>
int main() {
json::value v = { nullptr, "hello", 10 };
json::object o = {
{ "key", "value" },
{ "key2", 2 },
{ "key3", nullptr }
};
json::dump(std::cout, o);
}
Output:
{ "key": "value", "key2": 2, "key3": null }
- NaN and inf are currently allowed.
- Comments, e.g.
// stuff
is planned to be supported in the future. - The parser is not destructive.
- The parser is recursive descent.
- Numbers are stored in a
double
just like JSON butv.as<int>
and friends work with caution. - String is expected to be in UTF-8.
- Some errors are not caught but effort has been made to catch a lot of errors.