49#ifndef snicholls_core_adapters_nlohmann_decimal_json_hpp
50#define snicholls_core_adapters_nlohmann_decimal_json_hpp
56#include <snicholls/core/decimal.hpp>
65inline void to_json(nlohmann::json& j,
const decimal& d) { j = std::string(d.text().view()); }
72inline void from_json(
const nlohmann::json& j, decimal& d)
74 const std::string& s = detail::json_string_or_throw(j,
"snicholls::decimal",
"a decimal string");
75 const std::optional<decimal> r = decimal::parse(s);
77 detail::throw_json_error(
"snicholls::decimal",
"not canonical decimal text in range:", s);
void from_json(const nlohmann::json &j, decimal &d)
Reads canonical decimal text from a JSON string.
void to_json(nlohmann::json &j, const decimal &d)
Writes d as its canonical text, a JSON string.
snicholls::json_error and the nlohmann/json adapter layer: shared by every adapter.