17 using Value = std::variant<Null, String, Number, Bool, Object, Array>;
35 requires std::floating_point<T> || std::integral<T> && (!std::same_as<T, bool>)
38 requires std::constructible_from<std::string, T>
54 requires std::floating_point<T> || std::integral<T> && (!std::same_as<T, bool>)
57 requires std::constructible_from<std::string, T>
62 [[nodiscard]]
operator const Value&()
const;
68 [[nodiscard]]
bool IsOf()
const;
73 [[nodiscard]] T&
As();
75 [[nodiscard]]
const T&
As()
const;
82 [[nodiscard]]
const T&
AsRef()
const;
114 static std::expected<Json, Http::RequestError>
Parse(std::string_view input);
122 static std::expected<Json, Http::RequestError>
ParseText(std::string_view input,
bool copyData =
true,
bool checkFinal =
true);
125#pragma region Get Functions
159#pragma region Find Functions
192#pragma region Search Functions
198 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
201 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
204 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
207 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
211 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
214 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
219 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
222 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
225 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
228 template<
class Pred = PredicatePo
inter>
requires std::predicate<Pred, Json>
236 template<
class Callable>
237 constexpr decltype(
auto)
Visit(Callable&& callable);
240 template<
class Callable>
241 [[nodiscard]]
constexpr decltype(
auto)
Visit(Callable&& callable)
const;
246 inline static constexpr Null NullV{};
247 inline static Json NullJ{};
251#include <Thoth/NJson/Json.tpp>
Definition Definitions.hpp:19
std::vector< Json > Array
Definition Definitions.hpp:29
std::expected< CRefValWrapper, Http::RequestError > ExpCRefValWrapper
Definition Definitions.hpp:54
std::expected< ValWrapper, Http::RequestError > ExpValWrapper
Definition Definitions.hpp:62
std::optional< CRefValWrapper > OptCRefValWrapper
Definition Definitions.hpp:51
std::variant< int, JsonObjKey > Key
Definition Definitions.hpp:71
std::monostate Null
Definition Definitions.hpp:24
std::span< const Key > Keys
Definition Definitions.hpp:72
std::optional< RefValWrapper > OptRefValWrapper
Definition Definitions.hpp:50
std::optional< ValWrapper > OptValWrapper
Definition Definitions.hpp:59
std::expected< RefValWrapper, Http::RequestError > ExpRefValWrapper
Definition Definitions.hpp:53
bool operator==(const Json &other) const
Json(Json &&other) noexcept
std::optional< const T * > EnsureRef() const
ExpValWrapper FindCopyOrError(Keys keys) const
Same as successive calls to GetCopy. Return RequestError at the first fail.
ValWrapper FindCopyOrNull(Keys keys) const
Same as successive calls to GetCopy. Return null at the first fail.
Json & operator=(Json &&other) noexcept
ExpRefValWrapper SearchOrError(Pred &&pred)
Will search the childs for the first element that matches the predicate and return it,...
Json & operator=(Array &&child)
Json & operator=(Value &&newValue) noexcept
OptValWrapper GetAndMove(Key key) &&
Return (with move) the element with this index/key if this is an Object or Array, std::nullopt otherw...
OptRefValWrapper Find(Keys keys)
Same as successive calls to Get, std::nullopt at the first fail.
OptRefValWrapper Get(Key key)
Return a ref of the element with this index/key if this is an Object or Array, std::nullopt otherwise...
OptValWrapper SearchAndMove(Pred &&pred) &&
Will search the childs for the first element that matches the predicate and move it,...
Json(const Value &newValue)
ExpCRefValWrapper SearchOrError(Pred &&pred) const
Will search the childs for the first element that matches the predicate and return it,...
OptValWrapper SearchCopy(Pred &&pred) const
Will search the childs for the first element that matches the predicate and clone it,...
ExpValWrapper SearchAndMoveOrError(Pred &&pred) &&
Will search the childs for the first element that matches the predicate and move it,...
OptRefValWrapper Search(Pred &&pred)
Will search the childs for the first element that matches the predicate and return it,...
static T & AsType(Json &val)
ValWrapper FindAndMoveOrNull(Keys keys) &&
Same as successive calls to GetAndMove. Return null at the first fail.
std::variant< Null, String, Number, Bool, Object, Array > Value
Definition Json.hpp:17
ExpCRefValWrapper FindOrError(Keys keys) const
Same as successive calls to Get. Return RequestError at the first fail.
Json & operator=(T &&other)
Json & operator=(bool other)
static bool IsOfType(const Json &val)
constexpr decltype(auto) Visit(Callable &&callable)
convenient call to std::visit() on _value.
std::expected< const T *, Http::RequestError > EnsureRefOrError() const
ExpValWrapper FindAndMoveOrError(Keys keys) &&
Same as successive calls to Find. Return RequestError at the first fail.
ExpValWrapper GetAndMoveOrError(Key key) &&
Move the element with this index/key if this is an Object or Array. Return RequestError otherwise.
std::expected< T, Http::RequestError > EnsureMovOrError() &&
std::optional< T * > Ensure()
Json(Value &&newValue) noexcept
OptValWrapper FindCopy(Keys keys) const
Same as successive calls to GetCopy, std::nullopt at the first fail.
std::expected< T *, Http::RequestError > EnsureOrError()
std::expected< T *, Http::RequestError > EnsureMutOrError()
Json & operator=(const Array &child)
OptCRefValWrapper Find(Keys keys) const
Same as successive calls to Get, std::nullopt at the first fail.
Json & operator=(JsonObject &&other)
static std::expected< Json, Http::RequestError > Parse(std::string_view input)
Tries to parse the Json from a string.
ExpCRefValWrapper GetOrError(Key key) const
Return a ref of the element with this index/key if this is an Object or Array, RequestError otherwise...
ExpRefValWrapper FindOrError(Keys keys)
Same as successive calls to Get. Return RequestError at the first fail.
ValWrapper SearchAndMoveOrNull(Pred &&pred)
Will search the childs for the first element that matches the predicate and move it,...
Json & operator=(const Value &newValue)
ValWrapper SearchCopyOrNull(Pred &&pred) const
Will search the childs for the first element that matches the predicate and clone it,...
ExpValWrapper GetCopyOrError(Key key) const
Return a copy of the element with this index/key if this is an Object or Array, RequestError otherwis...
ExpValWrapper SearchCopyOrError(Pred &&pred) const
Will search the childs for the first element that matches the predicate and clone it,...
std::optional< T * > Ensure() const
ValWrapper GetCopyOrNull(Key key) const
Return a copy of the element with this index/key if this is an Object or Array, null otherwise.
Json & operator=(const Json &other)
OptValWrapper GetCopy(Key key) const
Return a copy of the element with this index/key if this is an Object or Array, std::nullopt otherwis...
OptValWrapper FindAndMove(Keys keys) &&
Same as successive calls to GetAndMove, std::nullopt at the first fail.
constexpr decltype(auto) Visit(Callable &&callable) const
convenient call to std::visit() on _value.
std::optional< T * > EnsureMut()
Json(const JsonObject &child)
ValWrapper GetAndMoveOrNull(Key key) &&
Move the element with this index/key if this is an Object or Array, null otherwise.
OptCRefValWrapper Search(Pred &&pred) const
Will search the childs for the first element that matches the predicate and return it,...
ExpRefValWrapper GetOrError(Key key)
Return a ref of the element with this index/key if this is an Object or Array, RequestError otherwise...
Json & operator=(const JsonObject &other)
std::optional< T > EnsureMov() &&
bool(*)(const Json &) PredicatePointer
Definition Json.hpp:18
std::expected< T *, Http::RequestError > EnsureOrError() const
OptCRefValWrapper Get(Key key) const
Return a ref of the element with this index/key if this is an Object or Array, std::nullopt otherwise...
static std::expected< Json, Http::RequestError > ParseText(std::string_view input, bool copyData=true, bool checkFinal=true)
Tries to parse the Json from a string.
Definition JsonObject.hpp:14