59#ifndef snicholls_core_adapters_nlohmann_json_hpp
60#define snicholls_core_adapters_nlohmann_json_hpp
79 explicit json_error(
const std::string& what) : std::runtime_error(what) {}
85[[noreturn]]
inline void throw_json_error(std::string_view type, std::string_view what, std::string_view input)
87 constexpr std::size_t max_quoted = 64;
88 std::string message(type);
89 message +=
" from_json: ";
92 message += input.substr(0, max_quoted);
93 if (input.size() > max_quoted) message +=
"...";
95 throw json_error(message);
99inline const std::string& json_string_or_throw(
const nlohmann::json& j, std::string_view type, std::string_view expected)
101 const auto* s = j.get_ptr<
const nlohmann::json::string_t*>();
102 if (s ==
nullptr) [[unlikely]] {
103 std::string what(
"expected ");
106 throw_json_error(type, what, j.type_name());
snicholls::json_error and the nlohmann/json adapter layer: shared by every adapter.
A JSON value that does not convert to or from a core type.
json_error(const std::string &what)
Constructs it.