10#include <userver/formats/common/items.hpp>
11#include <userver/formats/common/meta.hpp>
12#include <userver/formats/json/exception.hpp>
13#include <userver/formats/json/impl/types.hpp>
14#include <userver/formats/json/iterator.hpp>
15#include <userver/formats/json/serialize.hpp>
16#include <userver/formats/json/string_builder_fwd.hpp>
17#include <userver/formats/json/validate.hpp>
18#include <userver/formats/parse/common.hpp>
20USERVER_NAMESPACE_BEGIN
26namespace formats::
json {
28class InlineObjectBuilder;
29class InlineArrayBuilder;
30class MutableValueWrapper;
34impl::Value MakeJsonStringViewValue(std::string_view view);
88 static_assert(!
sizeof(
T),
89 "You're assigning to a temporary formats::json::Value! Use "
90 "formats::json::ValueBuilder for data modifications.");
178 template <
typename T>
184 template <
typename T,
typename First,
typename...
Rest>
190 template <
typename T>
195 template <
typename T>
200 template <
typename T,
typename First,
typename...
Rest>
339auto Value::As()
const {
340 static_assert(formats::
common::impl::kHasParse<Value, T>,
341 "There is no `Parse(const Value&, formats::parse::To<T>)` "
342 "in namespace of `T` or `formats::parse`. "
343 "Probably you forgot to include the "
344 "<userver/formats/parse/common_containers.hpp> or you "
345 "have not provided a `Parse` function overload.");
347 return Parse(*
this, formats::parse::To<T>{});
350bool Parse(
const Value& value,
parse::
To<
bool>);
352std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
354std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
356double Parse(
const Value& value,
parse::
To<
double>);
358std::string Parse(
const Value& value,
parse::
To<std::string>);
361bool Value::ConvertTo<
bool>()
const;
364int64_t Value::ConvertTo<int64_t>()
const;
367uint64_t Value::ConvertTo<uint64_t>()
const;
370double Value::ConvertTo<
double>()
const;
373std::string Value::ConvertTo<std::string>()
const;
375template <
typename T,
typename First,
typename... Rest>
376auto Value::As(First&& default_arg, Rest&&... more_default_args)
const {
377 if (IsMissing() || IsNull()) {
380 return decltype(As<T>())(std::forward<First>(default_arg),
381 std::forward<Rest>(more_default_args)...);
387auto Value::As(Value::DefaultConstructed)
const {
388 return (IsMissing() || IsNull()) ?
decltype(As<T>())() : As<T>();
392T Value::ConvertTo()
const {
393 if constexpr (formats::
common::impl::kHasConvert<Value, T>) {
394 return Convert(*
this, formats::
parse::
To<T>{});
395 }
else if constexpr (formats::
common::impl::kHasParse<Value, T>) {
396 return Parse(*
this, formats::
parse::
To<T>{});
400 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
401 "`Parse(const Value&, formats::parse::To<T>)`"
402 "in namespace of `T` or `formats::parse`. "
403 "Probably you have not provided a `Convert` function overload.");
407template <
typename T,
typename First,
typename... Rest>
408T Value::ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
409 if (IsMissing() || IsNull()) {
411 return T(std::forward<First>(default_arg),
412 std::forward<Rest>(more_default_args)...);
414 return ConvertTo<T>();
417inline Value Parse(
const Value& value,
parse::
To<Value>) {
return value; }
419std::chrono::microseconds Parse(
const Value& value,
420 parse::
To<std::chrono::microseconds>);
422std::chrono::milliseconds Parse(
const Value& value,
423 parse::
To<std::chrono::milliseconds>);
425std::chrono::minutes Parse(
const Value& value, parse::To<std::chrono::minutes>);
427std::chrono::hours Parse(
const Value& value, parse::To<std::chrono::hours>);
434using formats::
common::Items;
442json::Value operator
"" _json(
const char* str, std::size_t len);