diff --git a/tdutils/td/utils/JsonBuilder.h b/tdutils/td/utils/JsonBuilder.h index 7687e9fc7..ff65e4d3f 100644 --- a/tdutils/td/utils/JsonBuilder.h +++ b/tdutils/td/utils/JsonBuilder.h @@ -342,6 +342,10 @@ class JsonArrayScope : public JsonScope { } template JsonArrayScope &operator<<(const T &x) { + return (*this)(x); + } + template + JsonArrayScope &operator()(const T &x) { enter_value() << x; return *this; } @@ -391,7 +395,7 @@ class JsonObjectScope : public JsonScope { } jb_->enter_value() << key; *sb_ << ":"; - jb_->enter_value() << key; + jb_->enter_value() << value; return *this; } JsonObjectScope &operator<<(const JsonRaw &key_value) { @@ -785,6 +789,33 @@ auto json_object(F &&f) { return JsonObjectImpl(std::forward(f)); } +template +class JsonArrayImpl : Jsonable { + public: + JsonArrayImpl(F &&f) : f_(std::forward(f)) { + } + void store(JsonValueScope *scope) const { + auto array = scope->enter_array(); + f_(array); + } + + private: + F f_; +}; +template +auto json_array(F &&f) { + return JsonArrayImpl(std::forward(f)); +} + +template +auto json_array(const A &a, F &&f) { + return json_array([&a, &f](auto &arr) { + for (auto &x : a) { + arr(f(x)); + } + }); +} + bool has_json_object_field(JsonObject &object, Slice name); Result get_json_object_field(JsonObject &object, Slice name, JsonValue::Type type,