An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

## jsonpp

[![Build Status](https://travis-ci.org/Rapptz/jsonpp.svg?branch=master)](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
#include

int 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
#include

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
}

## 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.