9#include <userver/formats/common/items.hpp>
10#include <userver/formats/common/meta.hpp>
11#include <userver/formats/json/exception.hpp>
12#include <userver/formats/json/impl/types.hpp>
13#include <userver/formats/json/iterator.hpp>
14#include <userver/formats/json/serialize.hpp>
15#include <userver/formats/json/string_builder_fwd.hpp>
16#include <userver/formats/parse/common.hpp>
18USERVER_NAMESPACE_BEGIN
24namespace formats::
json {
26class InlineObjectBuilder;
27class InlineArrayBuilder;
28class MutableValueWrapper;
32impl::Value MakeJsonStringViewValue(std::string_view view);
83 static_assert(!
sizeof(
T),
84 "You're assigning to a temporary formats::json::Value! Use "
85 "formats::json::ValueBuilder for data modifications.");
172 template <
typename T>
178 template <
typename T,
typename First,
typename...
Rest>
184 template <
typename T>
189 template <
typename T>
194 template <
typename T,
typename First,
typename...
Rest>
313 static_assert(formats::
common::impl::kHasParse<Value, T>,
314 "There is no `Parse(const Value&, formats::parse::To<T>)` "
315 "in namespace of `T` or `formats::parse`. "
316 "Probably you forgot to include the "
317 "<userver/formats/parse/common_containers.hpp> or you "
318 "have not provided a `Parse` function overload.");
320 return Parse(*
this, formats::
parse::
To<T>{});
324bool Value::As<
bool>()
const;
327int64_t Value::As<int64_t>()
const;
330uint64_t Value::As<uint64_t>()
const;
333double Value::As<
double>()
const;
336std::string Value::As<std::string>()
const;
339bool Value::ConvertTo<
bool>()
const;
342int64_t Value::ConvertTo<int64_t>()
const;
345uint64_t Value::ConvertTo<uint64_t>()
const;
348double Value::ConvertTo<
double>()
const;
351std::string Value::ConvertTo<std::string>()
const;
353template <
typename T,
typename First,
typename... Rest>
354T Value::As(First&& default_arg, Rest&&... more_default_args)
const {
355 if (IsMissing() || IsNull()) {
358 return T(std::forward<First>(default_arg),
359 std::forward<Rest>(more_default_args)...);
365T Value::As(Value::DefaultConstructed)
const {
366 return (IsMissing() || IsNull()) ? T() : As<T>();
370T Value::ConvertTo()
const {
371 if constexpr (formats::
common::impl::kHasConvert<Value, T>) {
372 return Convert(*
this, formats::
parse::
To<T>{});
373 }
else if constexpr (formats::
common::impl::kHasParse<Value, T>) {
374 return Parse(*
this, formats::
parse::
To<T>{});
378 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
379 "`Parse(const Value&, formats::parse::To<T>)`"
380 "in namespace of `T` or `formats::parse`. "
381 "Probably you have not provided a `Convert` function overload.");
385template <
typename T,
typename First,
typename... Rest>
386T Value::ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
387 if (IsMissing() || IsNull()) {
389 return T(std::forward<First>(default_arg),
390 std::forward<Rest>(more_default_args)...);
392 return ConvertTo<T>();
395inline Value Parse(
const Value& value,
parse::
To<Value>) {
return value; }
402using formats::
common::Items;
410json::Value operator
"" _json(
const char* str, std::size_t len);