cannam@150: json11
cannam@150: ------
cannam@150: 
cannam@150: json11 is a tiny JSON library for C++11, providing JSON parsing and serialization.
cannam@150: 
cannam@150: The core object provided by the library is json11::Json. A Json object represents any JSON
cannam@150: value: null, bool, number (int or double), string (std::string), array (std::vector), or
cannam@150: object (std::map).
cannam@150: 
cannam@150: Json objects act like values. They can be assigned, copied, moved, compared for equality or
cannam@150: order, and so on. There are also helper methods Json::dump, to serialize a Json to a string, and
cannam@150: Json::parse (static) to parse a std::string as a Json object.
cannam@150: 
cannam@150: It's easy to make a JSON object with C++11's new initializer syntax:
cannam@150: 
cannam@150:     Json my_json = Json::object {
cannam@150:         { "key1", "value1" },
cannam@150:         { "key2", false },
cannam@150:         { "key3", Json::array { 1, 2, 3 } },
cannam@150:     };
cannam@150:     std::string json_str = my_json.dump();
cannam@150: 
cannam@150: There are also implicit constructors that allow standard and user-defined types to be
cannam@150: automatically converted to JSON. For example:
cannam@150: 
cannam@150:     class Point {
cannam@150:     public:
cannam@150:         int x;
cannam@150:         int y;
cannam@150:         Point (int x, int y) : x(x), y(y) {}
cannam@150:         Json to_json() const { return Json::array { x, y }; }
cannam@150:     };
cannam@150: 
cannam@150:     std::vector<Point> points = { { 1, 2 }, { 10, 20 }, { 100, 200 } };
cannam@150:     std::string points_json = Json(points).dump();
cannam@150: 
cannam@150: JSON values can have their values queried and inspected:
cannam@150: 
cannam@150:     Json json = Json::array { Json::object { { "k", "v" } } };
cannam@150:     std::string str = json[0]["k"].string_value();
cannam@150: 
cannam@150: More documentation is still to come. For now, see json11.hpp.