A small, self-contained JSON value type for librats. More...
#include "librats/util/rats_export.h"#include <cstdint>#include <initializer_list>#include <iosfwd>#include <stdexcept>#include <string>#include <type_traits>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| class | librats::JsonError |
| Thrown by the throwing parse path and by type-mismatched accessors. More... | |
| class | librats::Json |
| class | librats::Json::Object |
| Insertion-ordered string->Json map with O(1) average lookup. More... | |
| class | librats::Json::Iterator< Const > |
| class | librats::Json::ItemsProxy< Const > |
| A key/value view supporting structured bindings: for (auto&& [key, val] : obj.items()) { ... } For arrays, key() is the decimal index. More... | |
Namespaces | |
| namespace | librats |
Functions | |
| std::istream & | librats::operator>> (std::istream &is, Json &j) |
| std::ostream & | librats::operator<< (std::ostream &os, const Json &j) |
A small, self-contained JSON value type for librats.
librats::Json is a dynamically-typed JSON value with a deliberately nlohmann-flavoured surface so existing call sites read naturally:
Json j; // null j["name"] = "rats"; // becomes an object j["count"] = 42; // signed integer j["tags"] = Json::array(); // empty array j["tags"].push_back("p2p");
Json cfg = { // initializer-list "object" detection, {"version", 1}, // exactly like nlohmann: a list whose {"nodes", {{"id", "ab"}}}, // every element is a [string, value] pair }; // is treated as an object.
std::string text = j.dump(); // compact std::string nice = j.dump(2); // pretty, 2-space indent Json back = Json::parse(text); // throws on malformed input Json safe = Json::parse(text, nullptr, false); // never throws; see is_discarded()
Design notes:
Definition in file json.h.