2.0 preview

This commit is contained in:
Niels 2014-12-28 09:11:01 +01:00
parent d1ac3d9938
commit fbad7fac17
13 changed files with 16997 additions and 1315 deletions

View file

@ -6,9 +6,9 @@
There are myriads of [JSON](http://json.org) libraries out there, and each may even have its reason to exist. Our class had these design goals:
- **Trivial integration**. Our whole code consists of just two files: A header file `JSON.h` and a source file `JSON.cc`. That's it. No library, no subproject, no dependencies. The class is written in vanilla C++98 and -- if possible -- uses some features of C++11 such as move constructors. All in all, the class should require no adjustment of your compiler flags or project settings.
- **Trivial integration**. Our whole code consists of just two files: A header file `JSON.h` and a source file `JSON.cc`. That's it. No library, no subproject, no dependencies. The class is written in vanilla C++11. All in all, the class should require no adjustment of your compiler flags or project settings.
- **Intiuitve syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you know, what I mean.
- **Intuitive syntax**. In languages such as Python, JSON feels like a first class data type. We used all the operator magic of C++ to achieve the same feeling in your code. Check out the [examples below](#examples) and you know, what I mean.
Other aspects were not so important to us:
@ -16,7 +16,7 @@ Other aspects were not so important to us:
- **Speed**. We currently implement the parser as naive [recursive descent parser](http://en.wikipedia.org/wiki/Recursive_descent_parser) with hand coded string handling. It is fast enough, but a [LALR-parser](http://en.wikipedia.org/wiki/LALR_parser) with a decent regular expression processor should be even faster (but would consist of more files which makes the integration harder).
- **Rigourous standard compliance**. We followed the [specification](http://json.org) as close as possible, but did not invest too much in a 100% compliance with respect to Unicode support. As a result, there might be edge cases of false positives and false negatives, but as long as we have a hand-written parser, we won't invest too much to be fully compliant.
- **Rigorous standard compliance**. We followed the [specification](http://json.org) as close as possible, but did not invest too much in a 100% compliance with respect to Unicode support. As a result, there might be edge cases of false positives and false negatives, but as long as we have a hand-written parser, we won't invest too much to be fully compliant.
## Integration
@ -45,11 +45,17 @@ j["happy"] = true;
// add a string that is stored as std::string
j["name"] = "Niels";
// add a null object
j["nothing"] = nullptr;
// add an object inside the object
j["further"]["entry"] = 42;
// add an array that is stored as std::vector (C++11)
// add an array that is stored as std::vector
j["list"] = { 1, 0, 2 };
// add another object
j["object"] = { {"currency", "USD"}, {"value", "42.99"} };
```
### Input / Output
@ -65,6 +71,11 @@ std::cout << j;
These operators work for any subclasses of `std::istream` or `std::ostream`.
```cpp
// create object from string literal
JSON j = "{ \"pi\": 3.141, \"happy\": true }"_json;
```
### STL-like access
```cpp
@ -79,13 +90,13 @@ for (JSON::iterator it = j.begin(); it != j.end(); ++it) {
std::cout << *it << '\n';
}
// C++11 style
// range-based for
for (auto element : j) {
std::cout << element << '\n';
}
// getter/setter
std::string tmp = j[0];
const std::string tmp = j[0];
j[1] = 42;
// other stuff