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>
287 static_assert(formats::
common::impl::kHasParse<Value, T>,
288 "There is no `Parse(const Value&, formats::parse::To<T>)` "
289 "in namespace of `T` or `formats::parse`. "
290 "Probably you forgot to include the "
291 "<userver/formats/parse/common_containers.hpp> or you "
292 "have not provided a `Parse` function overload.");
294 return Parse(*
this, formats::
parse::
To<T>{});
298bool Value::As<
bool>()
const;
301int64_t Value::As<int64_t>()
const;
304uint64_t Value::As<uint64_t>()
const;
307double Value::As<
double>()
const;
310std::string Value::As<std::string>()
const;
313bool Value::ConvertTo<
bool>()
const;
316int64_t Value::ConvertTo<int64_t>()
const;
319uint64_t Value::ConvertTo<uint64_t>()
const;
322double Value::ConvertTo<
double>()
const;
325std::string Value::ConvertTo<std::string>()
const;
327template <
typename T,
typename First,
typename... Rest>
328T Value::As(First&& default_arg, Rest&&... more_default_args)
const {
329 if (IsMissing() || IsNull()) {
332 return T(std::forward<First>(default_arg),
333 std::forward<Rest>(more_default_args)...);
339T Value::As(Value::DefaultConstructed)
const {
340 return (IsMissing() || IsNull()) ? T() : As<T>();
344T Value::ConvertTo()
const {
345 if constexpr (formats::
common::impl::kHasConvert<Value, T>) {
346 return Convert(*
this, formats::
parse::
To<T>{});
347 }
else if constexpr (formats::
common::impl::kHasParse<Value, T>) {
348 return Parse(*
this, formats::
parse::
To<T>{});
352 "There is no `Convert(const Value&, formats::parse::To<T>)` or"
353 "`Parse(const Value&, formats::parse::To<T>)`"
354 "in namespace of `T` or `formats::parse`. "
355 "Probably you have not provided a `Convert` function overload.");
359template <
typename T,
typename First,
typename... Rest>
360T Value::ConvertTo(First&& default_arg, Rest&&... more_default_args)
const {
361 if (IsMissing() || IsNull()) {
363 return T(std::forward<First>(default_arg),
364 std::forward<Rest>(more_default_args)...);
366 return ConvertTo<T>();
369inline Value Parse(
const Value& value,
parse::
To<Value>) {
return value; }
376using formats::
common::Items;
384json::Value operator
"" _json(
const char* str, std::size_t len);