1 #pragma once
2 
3 #include <nlohmann/json.hpp>
4 
5 #include <format>
6 
7 // Clang-tidy would rather these be static, but using static causes the template
8 // specialization to not function.  Ignore the warning.
9 // NOLINTBEGIN(readability-convert-member-functions-to-static, cert-dcl58-cpp)
10 
11 template <>
12 struct std::formatter<nlohmann::json::json_pointer>
13 {
parsestd::formatter14     constexpr auto parse(std::format_parse_context& ctx)
15     {
16         return ctx.begin();
17     }
formatstd::formatter18     auto format(const nlohmann::json::json_pointer& ptr, auto& ctx) const
19     {
20         return std::format_to(ctx.out(), "{}", ptr.to_string());
21     }
22 };
23 
24 template <>
25 struct std::formatter<nlohmann::json>
26 {
parsestd::formatter27     static constexpr auto parse(std::format_parse_context& ctx)
28     {
29         return ctx.begin();
30     }
formatstd::formatter31     auto format(const nlohmann::json& json, auto& ctx) const
32     {
33         return std::format_to(
34             ctx.out(), "{}",
35             json.dump(-1, ' ', false,
36                       nlohmann::json::error_handler_t::replace));
37     }
38 };
39 // NOLINTEND(readability-convert-member-functions-to-static, cert-dcl58-cpp)
40