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);
87 static_assert(!
sizeof(
T),
88 "You're assigning to a temporary formats::json::Value! Use "
89 "formats::json::ValueBuilder for data modifications.");
177 template <
typename T>
183 template <
typename T,
typename First,
typename...
Rest>
189 template <
typename T>
194 template <
typename T>
199 template <
typename T,
typename First,
typename...
Rest>
338auto Value::As()
const {
339 static_assert(formats::
common::impl::kHasParse<Value, T>,
340 "There is no `Parse(const Value&, formats::parse::To<T>)` "
341 "in namespace of `T` or `formats::parse`. "
342 "Probably you forgot to include the "
343 "<userver/formats/parse/common_containers.hpp> or you "
344 "have not provided a `Parse` function overload.");
346 return Parse(*
this, formats::parse::To<T>{});
349bool Parse(
const Value& value,
parse::
To<
bool>);
351std::int64_t Parse(
const Value& value,
parse::
To<std::int64_t>);
353std::uint64_t Parse(
const Value& value,
parse::
To<std::uint64_t>);
355double Parse(
const Value& value,
parse::
To<
double>);
357std::string Parse(
const Value& value,
parse::
To<std::string>);
360bool Value::ConvertTo<
bool>()
const;
363int64_t Value::ConvertTo<int64_t>()
const;
366uint64_t Value::ConvertTo<uint64_t>()
const;
369double Value::ConvertTo<
double>()
const;
372std::string Value::ConvertTo<std::string>()
const;
374template <
typename T,
typename First,
typename... Rest>
375auto Value::As(First&& default_arg, Rest&&... more_default_args)
const {
376 if (IsMissing() || IsNull()) {
379 return decltype(As<T>())(std::forward<First>(default_arg),
380 std::forward<Rest>(more_default_args)...);
386auto Value::As(Value::DefaultConstructed)
const {
387 return (IsMissing() || IsNull()) ?
decltype(As<T>())() : As<T>();
391T Value::ConvertTo()
const {
392 if constexpr (formats::
common::impl::kHasConvert<Value, T>) {
393 return Convert(*
this, formats::
parse::
To<T>{});
394 }
else if constexpr (formats::
common::impl::kHasParse<Value, T>) {
395 return Parse(*
this, formats::
parse::
To<T>{});
399 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
400 "`Parse(const Value&, formats::parse::To<T>)`"
401 "in namespace of `T` or `formats::parse`. "
402 "Probably you have not provided a `Convert` function overload.");
406template <
typename T,
typename First,
typename... Rest>
407T Value::ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
408 if (IsMissing() || IsNull()) {
410 return T(std::forward<First>(default_arg),
411 std::forward<Rest>(more_default_args)...);
413 return ConvertTo<T>();
416inline Value Parse(
const Value& value,
parse::
To<Value>) {
return value; }
418std::chrono::milliseconds Parse(
const Value& value,
419 parse::
To<std::chrono::milliseconds>);
421std::chrono::minutes Parse(
const Value& value, parse::To<std::chrono::minutes>);
423std::chrono::hours Parse(
const Value& value, parse::To<std::chrono::hours>);
430using formats::
common::Items;
438json::Value operator
"" _json(
const char* str, std::size_t len);