Lines Matching full:json

25 This example uses C++17's std::variant to build a toy JSON type. JSON can hold
26 various types including strings, and JSON's object type is a map with string
37 include!("example/include/json.h");
39 #[cxx_name = "json"]
40 type Json;
44 fn isNull(self: &Json) -> bool;
45 fn isNumber(self: &Json) -> bool;
46 fn isString(self: &Json) -> bool;
47 fn isArray(self: &Json) -> bool;
48 fn isObject(self: &Json) -> bool;
50 fn getNumber(self: &Json) -> f64;
51 fn getString(self: &Json) -> &CxxString;
52 fn getArray(self: &Json) -> &CxxVector<Json>;
53 fn getObject(self: &Json) -> &Object;
56 fn get<'a>(self: &'a Object, key: &CxxString) -> &'a Json;
58 fn load_config() -> UniquePtr<Json>;
71 // include/json.h
80 class json final {
82 static const json null;
85 using array = std::vector<json>;
86 using object = std::map<string, json>;
88 json() noexcept = default;
89 json(const json &) = default;
90 json(json &&) = default;
92 json(T &&...value) : value(std::forward<T>(value)...) {}
109 using object = json::object;
111 std::unique_ptr<json> load_config();
115 // include/json.cc
117 #include "example/include/json.h"
121 const json json::null{};
122 bool json::isNull() const { return std::holds_alternative<std::monostate>(value); }
123 bool json::isNumber() const { return std::holds_alternative<number>(value); }
124 bool json::isString() const { return std::holds_alternative<string>(value); }
125 bool json::isArray() const { return std::holds_alternative<array>(value); }
126 bool json::isObject() const { return std::holds_alternative<object>(value); }
127 json::number json::getNumber() const { return std::get<number>(value); }
128 const json::string &json::getString() const { return std::get<string>(value); }
129 const json::array &json::getArray() const { return std::get<array>(value); }
130 const json::object &json::getObject() const { return std::get<object>(value); }
132 std::unique_ptr<json> load_config() {
133 return std::make_unique<json>(
134 std::in_place_type<json::object>,
135 std::initializer_list<std::pair<const std::string, json>>{
138 {"repository", json::null}});