https://github.com/rapptz/jsonpp
C++11 JSON parser and writer
https://github.com/rapptz/jsonpp
c-plus-plus c-plus-plus-11 json-parser
Last synced: 23 days ago
JSON representation
C++11 JSON parser and writer
- Host: GitHub
- URL: https://github.com/rapptz/jsonpp
- Owner: Rapptz
- License: mit
- Created: 2014-06-19T02:26:45.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-07-10T01:15:02.000Z (almost 8 years ago)
- Last Synced: 2025-04-09T17:05:01.669Z (23 days ago)
- Topics: c-plus-plus, c-plus-plus-11, json-parser
- Language: C++
- Homepage: http://rapptz.github.io/jsonpp/
- Size: 346 KB
- Stars: 21
- Watchers: 9
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## jsonpp
[](https://travis-ci.org/Rapptz/jsonpp)
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.
## Features
- Easy to use with a simple API.
- No special null, array, or object types.
- `json::null` is a type alias to `std::nullptr_t`.
- `json::array` is `std::vector`.
- `json::object` is `std::map`.
- Decently fast.
- No dependencies, only the standard library and a C++11 compiler.## Documentation
Documentation is an on going process and can be found [here][docs]. Amongst documentation you
can also find examples.[docs]: http://rapptz.github.io/jsonpp
## Example usage
#### Parsing
```cpp
#include
#includeint main() {
json::parser p;
json::value v;
try {
p.parse("[null, \"hello\", 10.0]", v);
if(v.is()) {
for(auto&& val : v.as()) {
std::cout << val.as("stuff");
}
}
}
catch(const std::exception& e) {
std::cerr << e.what() << '\n';
}
}
```Output:
stuff hello stuff#### Writing
```cpp
#include
#includeint 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
}## Quirks and Specification
- 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 but `v.as` 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.