annotate json/json11/README.md @ 66:6f160dee1192

Instead of using separate values and b64values entries in JSON serialisations, allow numeric arrays to be replaced by b64 variants wherever they appear (discriminating by type). Also rename values to featureValues in feature throughout, as values turns out to be a hazardous name in a JS context. Finally use Array instead of Text for array encoding (seems clearer).
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 27 Sep 2016 15:04:59 +0100
parents 6e8607ebad03
children
rev   line source
c@5 1 json11
c@5 2 ------
c@5 3
c@5 4 json11 is a tiny JSON library for C++11, providing JSON parsing and serialization.
c@5 5
c@5 6 The core object provided by the library is json11::Json. A Json object represents any JSON
c@5 7 value: null, bool, number (int or double), string (std::string), array (std::vector), or
c@5 8 object (std::map).
c@5 9
c@5 10 Json objects act like values. They can be assigned, copied, moved, compared for equality or
c@5 11 order, and so on. There are also helper methods Json::dump, to serialize a Json to a string, and
c@5 12 Json::parse (static) to parse a std::string as a Json object.
c@5 13
c@5 14 It's easy to make a JSON object with C++11's new initializer syntax:
c@5 15
c@5 16 Json my_json = Json::object {
c@5 17 { "key1", "value1" },
c@5 18 { "key2", false },
c@5 19 { "key3", Json::array { 1, 2, 3 } },
c@5 20 };
c@5 21 std::string json_str = my_json.dump();
c@5 22
c@5 23 There are also implicit constructors that allow standard and user-defined types to be
c@5 24 automatically converted to JSON. For example:
c@5 25
c@5 26 class Point {
c@5 27 public:
c@5 28 int x;
c@5 29 int y;
c@5 30 Point (int x, int y) : x(x), y(y) {}
c@5 31 Json to_json() const { return Json::array { x, y }; }
c@5 32 };
c@5 33
c@5 34 std::vector<Point> points = { { 1, 2 }, { 10, 20 }, { 100, 200 } };
c@5 35 std::string points_json = Json(points).dump();
c@5 36
c@5 37 JSON values can have their values queried and inspected:
c@5 38
c@5 39 Json json = Json::array { Json::object { { "k", "v" } } };
c@5 40 std::string str = json[0]["k"].string_value();
c@5 41
c@5 42 More documentation is still to come. For now, see json11.hpp.