Skip to content

Commit

Permalink
Add license and README.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Jun 18, 2014
1 parent fd54ef7 commit 6006b0d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014 Rapptz

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## 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.

## Features

- Easy to use with an easy to use API.
- No special null, array, or object types.
- `json::null` is a type alias to `std::nullptr_t`.
- `json::array` is `std::vector<json::value>`.
- `json::object` is `std::map<std::string, json::value>`.
- Decently fast.
- No dependencies, only the standard library and a C++11 compiler.

## Example usage

#### Parsing

```cpp
#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.get<std::string>("stuff");
}
}
}
catch(const std::exception& e) {
std::cerr << e.what() << '\n';
}
}
```

Output:
<pre>
stuff hello stuff
</pre>

#### Writing

```cpp
#include <jsonpp/value.hpp>
#include <iostream>

int main() {
json::value v = { nullptr, "hello", 10 };
std::cout << v.to_string();
}
```

Output:
<pre>
[null, "hello", 10]
</pre>

## Quirks and Specification

- NaN and inf are currently allowed.
- Comments, e.g. `// stuff` is planned to be supported in the future.
- The string is only passed once.
- The parser is not destructive.
- The parser is recursive descent.
- `int` and `double` types are aliased to be the same.
1 change: 1 addition & 0 deletions jsonpp/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define JSON_TYPE_TRAITS_HPP

#include <type_traits>
#include <string>

namespace json {
inline namespace v1 {
Expand Down

0 comments on commit 6006b0d

Please sign in to comment.