// SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include #include #include #include #include namespace bmh::cli { struct Json { using Array = std::vector; using Object = std::map>; using Value = std::variant; Value value = nullptr; Json() = default; Json(std::nullptr_t) : value(nullptr) {} Json(bool v) : value(v) {} Json(std::int64_t v) : value(v) {} Json(int v) : value(std::int64_t(v)) {} Json(std::string v) : value(std::move(v)) {} Json(const char* v) : value(std::string(v)) {} Json(Array v) : value(std::move(v)) {} Json(Object v) : value(std::move(v)) {} const Object* object() const { return std::get_if(&value); } Object* object() { return std::get_if(&value); } const Array* array() const { return std::get_if(&value); } const std::string* string() const { return std::get_if(&value); } const std::int64_t* integer() const { return std::get_if(&value); } const bool* boolean() const { return std::get_if(&value); } }; class JsonError final : public std::runtime_error { public: using std::runtime_error::runtime_error; }; Json parse_json(std::string_view source); std::string dump_json(const Json& value); } // namespace bmh::cli