9#include <glaze/json.hpp>
35 static constexpr glz::opts
ReadOptions{.comments =
true, .error_on_unknown_keys =
false};
45 template <
class T, auto Options = ReadOptions>
51 return std::unexpected(
text.error());
63 template <
class T, auto Options = ReadOptions>
67 if (
auto ec = glz::read<Options>(value,
text))
95 template <
class T,
auto Options = glz::opts{}>
96 static std::string
Write(
const T& value)
98 auto written = glz::write<Options>(value);
124 if (
node.is_string())
128 else if (
node.is_object())
135 else if (
node.is_array())
137 for (
auto&
child :
node.get<glz::generic::array_t>())
168 const std::string
key(
175 if (
dot == std::string_view::npos)
182 if (
node->is_string())
184 return node->get_string();
187 if (
node->is_number() ||
node->is_boolean())
191 return std::move(*
dumped);
System.Text.Json-style helpers for mapping C++ types to and from JSON.
static std::string WritePretty(const T &value)
Serialize value as prettified JSON.
static constexpr PrettyOpts PrettyOptions
static std::string GetStringByPath(std::string_view jsonText, std::string_view dotPath)
Descend a dot-separated path (e.g. "data.room.code") in jsonText.
static std::string Write(const T &value)
Serialize value as compact JSON.
static Result< T > ReadFile(std::string_view path)
Parse path (resolved via ResolvePath) into T.
static Result< glz::generic > ParseDocument(std::string_view text)
Parse free-form JSON whose shape is not known at compile time.
static void SubstituteTokens(glz::generic &node, const Tokens &tokens)
Recursively replace {key} tokens in every string value of node.
static std::string GetString(const glz::generic &root, std::string_view dotPath)
static constexpr glz::opts ReadOptions
static Result< T > Read(std::string_view text)
As ReadFile, over text already in hand.
static constexpr glz::opts StrictReadOptions
Owns a plugin's settings and republishes them whole on every Load.
static std::string SubstituteTokens(std::string text, const Tokens &tokens)
void Error(std::format_string< Args... > fmt, Args &&... args)
Result< std::string > ReadAllText(std::string_view path)
Read path (resolved via ResolvePath) into a string.
std::map< std::string, std::string > Tokens
std::expected< T, Error > Result
static Error Invalid(std::string detail)
uint8_t indentation_width