Copy of dropbox/json11 repository with uint64_t/int64_t support
 
 
 
Go to file
j4cbo 765cee3ed1 Merge pull request #39 from PollRobots/use-cmake
Add cmake support
2015-10-19 16:30:01 -07:00
.gitignore Initial commit 2013-09-06 15:07:12 -07:00
CMakeLists.txt Add cmake support 2015-08-19 14:53:28 -07:00
LICENSE.txt Add LICENSE.txt; some minor cleanups 2013-10-01 19:05:12 -07:00
Makefile Make test.cpp compilable with GCC. 2015-06-17 18:02:34 -07:00
README.md Initial commit 2013-09-06 15:07:12 -07:00
json11.cpp When dumping non-finite floating point values, output 'null'. 2015-06-04 10:35:12 +02:00
json11.hpp Identify map- and vector-like objects in a VS14-compatible way 2014-08-13 15:12:44 -07:00
test.cpp Fixes bug in parse_from_stdin 2015-08-19 15:00:12 -07:00

README.md

json11

json11 is a tiny JSON library for C++11, providing JSON parsing and serialization.

The core object provided by the library is json11::Json. A Json object represents any JSON value: null, bool, number (int or double), string (std::string), array (std::vector), or object (std::map).

Json objects act like values. They can be assigned, copied, moved, compared for equality or order, and so on. There are also helper methods Json::dump, to serialize a Json to a string, and Json::parse (static) to parse a std::string as a Json object.

It's easy to make a JSON object with C++11's new initializer syntax:

Json my_json = Json::object {
    { "key1", "value1" },
    { "key2", false },
    { "key3", Json::array { 1, 2, 3 } },
};
std::string json_str = my_json.dump();

There are also implicit constructors that allow standard and user-defined types to be automatically converted to JSON. For example:

class Point {
public:
    int x;
    int y;
    Point (int x, int y) : x(x), y(y) {}
    Json to_json() const { return Json::array { x, y }; }
};

std::vector<Point> points = { { 1, 2 }, { 10, 20 }, { 100, 200 } };
std::string points_json = Json(points).dump();

JSON values can have their values queried and inspected:

Json json = Json::array { Json::object { { "k", "v" } } };
std::string str = json[0]["k"].string_value();

More documentation is still to come. For now, see json11.hpp.