core-adapters 0.1.3
Third-party adapters for snicholls-core: nanobind helpers, nlohmann/json hooks, the snicholls_core Python package
Loading...
Searching...
No Matches
uuid_json.hpp
Go to the documentation of this file.
1//
2// uuid_json.hpp
3// core-adapters
4//
5// Copyright 2010-2026 Saxon Herschel Nicholls
6//
7
44
45#ifndef snicholls_core_adapters_nlohmann_uuid_json_hpp
46#define snicholls_core_adapters_nlohmann_uuid_json_hpp
47
48#include <optional>
49#include <string>
50
52#include <snicholls/core/uuid.hpp>
53
54namespace snicholls {
55
61inline void to_json(nlohmann::json& j, const uuid& u) { j = std::string(to_text(u).view()); }
62
68inline void from_json(const nlohmann::json& j, uuid& u)
69{
70 const std::string& s = detail::json_string_or_throw(j, "snicholls::uuid", "a UUID string");
71 const std::optional<uuid> r = parse_uuid(s);
72 if (!r) [[unlikely]]
73 detail::throw_json_error("snicholls::uuid", "not a canonical 8-4-4-4-12 UUID:", s);
74 u = *r;
75}
76
77} // namespace snicholls
78
79#endif /* snicholls_core_adapters_nlohmann_uuid_json_hpp */
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.