50#ifndef snicholls_core_adapters_nlohmann_time_json_hpp
51#define snicholls_core_adapters_nlohmann_time_json_hpp
54#include <system_error>
57#include <snicholls/core/time/rfc3339.hpp>
58#include <snicholls/core/time/utc.hpp>
68template <utc_duration D>
69void to_json(nlohmann::json& j,
const utc<D>& t)
71 const rfc3339_text text = to_text(t);
72 if (!text) [[unlikely]]
73 throw json_error(
"snicholls::utc to_json: a year outside 0000..9999 has no RFC 3339 form");
74 j = std::string(text.view());
83template <utc_duration D>
86 const std::string& s = detail::json_string_or_throw(j,
"snicholls::utc",
"an RFC 3339 string");
87 const parse_result<utc<D>> r = parse_utc<D>(s);
89 detail::throw_json_error(
"snicholls::utc",
90 r.error() == std::errc::result_out_of_range ?
"out of range or too precise:"
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.
A JSON value that does not convert to or from a core type.