annotate ext/json11/README.md @ 218:ea8994465322

Rebuild these for capnp v0.6. But it would probably be better at this point not to commit them, as the main reason they are in the repo is because the compiler wasn't available for Visual Studio builds, and that's no longer the case.
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 09 May 2017 11:46:23 +0100
parents bf8e3e7dd7de
children
rev   line source
cannam@150 1 json11
cannam@150 2 ------
cannam@150 3
cannam@150 4 json11 is a tiny JSON library for C++11, providing JSON parsing and serialization.
cannam@150 5
cannam@150 6 The core object provided by the library is json11::Json. A Json object represents any JSON
cannam@150 7 value: null, bool, number (int or double), string (std::string), array (std::vector), or
cannam@150 8 object (std::map).
cannam@150 9
cannam@150 10 Json objects act like values. They can be assigned, copied, moved, compared for equality or
cannam@150 11 order, and so on. There are also helper methods Json::dump, to serialize a Json to a string, and
cannam@150 12 Json::parse (static) to parse a std::string as a Json object.
cannam@150 13
cannam@150 14 It's easy to make a JSON object with C++11's new initializer syntax:
cannam@150 15
cannam@150 16 Json my_json = Json::object {
cannam@150 17 { "key1", "value1" },
cannam@150 18 { "key2", false },
cannam@150 19 { "key3", Json::array { 1, 2, 3 } },
cannam@150 20 };
cannam@150 21 std::string json_str = my_json.dump();
cannam@150 22
cannam@150 23 There are also implicit constructors that allow standard and user-defined types to be
cannam@150 24 automatically converted to JSON. For example:
cannam@150 25
cannam@150 26 class Point {
cannam@150 27 public:
cannam@150 28 int x;
cannam@150 29 int y;
cannam@150 30 Point (int x, int y) : x(x), y(y) {}
cannam@150 31 Json to_json() const { return Json::array { x, y }; }
cannam@150 32 };
cannam@150 33
cannam@150 34 std::vector<Point> points = { { 1, 2 }, { 10, 20 }, { 100, 200 } };
cannam@150 35 std::string points_json = Json(points).dump();
cannam@150 36
cannam@150 37 JSON values can have their values queried and inspected:
cannam@150 38
cannam@150 39 Json json = Json::array { Json::object { { "k", "v" } } };
cannam@150 40 std::string str = json[0]["k"].string_value();
cannam@150 41
cannam@150 42 More documentation is still to come. For now, see json11.hpp.