18#ifndef INCLUDE_WPI_JSON_HPP_
19#define INCLUDE_WPI_JSON_HPP_
24#include <initializer_list>
36#include <wpi/detail/conversions/from_json.h>
37#include <wpi/detail/conversions/to_json.h>
38#include <wpi/detail/exceptions.h>
39#include <wpi/detail/hash.h>
40#include <wpi/detail/input/binary_reader.h>
41#include <wpi/detail/input/input_adapters.h>
42#include <wpi/detail/input/lexer.h>
43#include <wpi/detail/input/parser.h>
44#include <wpi/detail/iterators/internal_iterator.h>
45#include <wpi/detail/iterators/iter_impl.h>
46#include <wpi/detail/iterators/iteration_proxy.h>
47#include <wpi/detail/iterators/json_reverse_iterator.h>
48#include <wpi/detail/iterators/primitive_iterator.h>
49#include <wpi/detail/json_custom_base_class.h>
50#include <wpi/detail/json_pointer.h>
51#include <wpi/detail/json_ref.h>
52#include <wpi/detail/macro_scope.h>
53#include <wpi/detail/string_concat.h>
54#include <wpi/detail/string_escape.h>
55#include <wpi/detail/meta/cpp_future.h>
56#include <wpi/detail/meta/type_traits.h>
57#include <wpi/detail/output/binary_writer.h>
58#include <wpi/detail/output/output_adapters.h>
59#include <wpi/detail/output/serializer.h>
60#include <wpi/detail/value_t.h>
64#if defined(JSON_HAS_CPP_17)
65 #if JSON_HAS_STATIC_RTTI
68 #include <string_view>
76WPI_JSON_NAMESPACE_BEGIN
96WPI_BASIC_JSON_TPL_DECLARATION
98 :
public ::wpi::detail::json_base_class<CustomBaseClass>
104 friend class ::wpi::json_pointer;
108 template<
typename BasicJsonType,
typename InputType>
109 friend class ::wpi::detail::parser;
110 friend ::wpi::detail::serializer<basic_json>;
111 template<
typename BasicJsonType>
112 friend class ::wpi::detail::iter_impl;
113 template<
typename BasicJsonType,
typename CharType>
114 friend class ::wpi::detail::binary_writer;
115 template<
typename BasicJsonType,
typename InputType,
typename SAX>
116 friend class ::wpi::detail::binary_reader;
117 template<
typename BasicJsonType>
118 friend class ::wpi::detail::json_sax_dom_parser;
119 template<
typename BasicJsonType>
120 friend class ::wpi::detail::json_sax_dom_callback_parser;
121 friend class ::wpi::detail::exception;
124 using basic_json_t = WPI_BASIC_JSON_TPL;
125 using json_base_class_t = ::wpi::detail::json_base_class<CustomBaseClass>;
127 JSON_PRIVATE_UNLESS_TESTED:
129 using lexer = ::wpi::detail::lexer_base<basic_json>;
131 template<
typename InputAdapterType>
132 static ::wpi::detail::parser<basic_json, InputAdapterType>
parser(
133 InputAdapterType adapter,
134 detail::parser_callback_t<basic_json>cb =
nullptr,
135 const bool allow_exceptions =
true,
136 const bool ignore_comments =
false
139 return ::wpi::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
140 std::move(cb), allow_exceptions, ignore_comments);
144 using primitive_iterator_t = ::wpi::detail::primitive_iterator_t;
145 template<
typename BasicJsonType>
146 using internal_iterator = ::wpi::detail::internal_iterator<BasicJsonType>;
147 template<
typename BasicJsonType>
148 using iter_impl = ::wpi::detail::iter_impl<BasicJsonType>;
149 template<
typename Iterator>
150 using iteration_proxy = ::wpi::detail::iteration_proxy<Iterator>;
151 template<
typename Base>
using json_reverse_iterator = ::wpi::detail::json_reverse_iterator<Base>;
153 template<
typename CharType>
154 using output_adapter_t = ::wpi::detail::output_adapter_t<CharType>;
156 template<
typename InputType>
157 using binary_reader = ::wpi::detail::binary_reader<basic_json, InputType>;
158 template<
typename CharType>
using binary_writer = ::wpi::detail::binary_writer<basic_json, CharType>;
166 template<
typename T,
typename SFINAE>
222 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
224 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
251 result[
"copyright"] =
"(C) 2013-2023 Niels Lohmann";
252 result[
"name"] =
"JSON for Modern C++";
253 result[
"url"] =
"https://github.com/nlohmann/json";
254 result[
"version"][
"string"] =
255 detail::concat(std::to_string(WPI_JSON_VERSION_MAJOR),
'.',
256 std::to_string(WPI_JSON_VERSION_MINOR),
'.',
257 std::to_string(WPI_JSON_VERSION_PATCH));
258 result[
"version"][
"major"] = WPI_JSON_VERSION_MAJOR;
259 result[
"version"][
"minor"] = WPI_JSON_VERSION_MINOR;
260 result[
"version"][
"patch"] = WPI_JSON_VERSION_PATCH;
263 result[
"platform"] =
"win32";
264#elif defined __linux__
265 result[
"platform"] =
"linux";
266#elif defined __APPLE__
267 result[
"platform"] =
"apple";
268#elif defined __unix__
269 result[
"platform"] =
"unix";
271 result[
"platform"] =
"unknown";
274#if defined(__ICC) || defined(__INTEL_COMPILER)
275 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
276#elif defined(__clang__)
277 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
278#elif defined(__GNUC__) || defined(__GNUG__)
279 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", detail::concat(
280 std::to_string(__GNUC__),
'.',
281 std::to_string(__GNUC_MINOR__),
'.',
282 std::to_string(__GNUC_PATCHLEVEL__))
285#elif defined(__HP_cc) || defined(__HP_aCC)
286 result[
"compiler"] =
"hp"
287#elif defined(__IBMCPP__)
288 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
289#elif defined(_MSC_VER)
290 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
292 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
293#elif defined(__SUNPRO_CC)
294 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
296 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
299#if defined(_MSVC_LANG)
300 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
301#elif defined(__cplusplus)
302 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
304 result[
"compiler"][
"c++"] =
"unknown";
322#if defined(JSON_HAS_CPP_14)
335 AllocatorType<std::pair<
const StringType,
340 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
364 using binary_t = wpi::byte_container_with_subtype<BinaryType>;
375 template<
typename T,
typename... Args>
377 static T* create(Args&& ... args)
379 AllocatorType<T> alloc;
380 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
382 auto deleter = [&](T * obj)
384 AllocatorTraits::deallocate(alloc, obj, 1);
386 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
387 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
388 JSON_ASSERT(obj !=
nullptr);
389 return obj.release();
396 JSON_PRIVATE_UNLESS_TESTED:
442 json_value() =
default;
444 json_value(
boolean_t v) noexcept : boolean(v) {}
456 case value_t::object:
458 object = create<object_t>();
464 array = create<array_t>();
468 case value_t::string:
470 string = create<string_t>(
"");
474 case value_t::binary:
476 binary = create<binary_t>();
480 case value_t::boolean:
486 case value_t::number_integer:
492 case value_t::number_unsigned:
498 case value_t::number_float:
510 case value_t::discarded:
516 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3",
nullptr));
556 (t == value_t::object &&
object ==
nullptr) ||
557 (t == value_t::array && array ==
nullptr) ||
558 (t == value_t::string &&
string ==
nullptr) ||
559 (t == value_t::binary && binary ==
nullptr)
565 if (t == value_t::array || t == value_t::object)
568 std::vector<basic_json> stack;
571 if (t == value_t::array)
573 stack.reserve(
array->size());
574 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
579 for (
auto&& it : *
object)
581 stack.push_back(std::move(it.second));
585 while (!stack.empty())
588 basic_json current_item(std::move(stack.back()));
593 if (current_item.is_array())
595 std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));
597 current_item.m_data.m_value.array->clear();
599 else if (current_item.is_object())
601 for (
auto&& it : *current_item.m_data.m_value.object)
603 stack.push_back(std::move(it.second));
606 current_item.m_data.m_value.object->clear();
616 case value_t::object:
618 AllocatorType<object_t> alloc;
619 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
620 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
626 AllocatorType<array_t> alloc;
627 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
628 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
632 case value_t::string:
634 AllocatorType<string_t> alloc;
635 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
636 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
640 case value_t::binary:
642 AllocatorType<binary_t> alloc;
643 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
644 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
649 case value_t::boolean:
650 case value_t::number_integer:
651 case value_t::number_unsigned:
652 case value_t::number_float:
653 case value_t::discarded:
681 void assert_invariant(
bool check_parents =
true) const noexcept
683 JSON_ASSERT(
m_data.m_type != value_t::object ||
m_data.m_value.object !=
nullptr);
684 JSON_ASSERT(
m_data.m_type != value_t::array ||
m_data.m_value.array !=
nullptr);
685 JSON_ASSERT(
m_data.m_type != value_t::string ||
m_data.m_value.string !=
nullptr);
686 JSON_ASSERT(
m_data.m_type != value_t::binary ||
m_data.m_value.binary !=
nullptr);
694 return j.m_parent ==
this;
699 static_cast<void>(check_parents);
709 for (
auto& element : *
m_data.m_value.array)
711 element.m_parent =
this;
716 case value_t::object:
718 for (
auto& element : *
m_data.m_value.object)
720 element.second.m_parent =
this;
726 case value_t::string:
727 case value_t::boolean:
728 case value_t::number_integer:
729 case value_t::number_unsigned:
730 case value_t::number_float:
731 case value_t::binary:
732 case value_t::discarded:
739 iterator set_parents(
iterator it,
typename iterator::difference_type count_set_parents)
742 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
744 (it + i)->m_parent =
this;
747 static_cast<void>(count_set_parents);
752 reference set_parent(
reference j, std::size_t old_capacity =
static_cast<std::size_t
>(-1))
755 if (old_capacity !=
static_cast<std::size_t
>(-1))
758 JSON_ASSERT(
type() == value_t::array);
769#ifdef JSON_HEDLEY_MSVC_VERSION
770#pragma warning(push )
771#pragma warning(disable : 4127)
773 if (detail::is_ordered_map<object_t>::value)
778#ifdef JSON_HEDLEY_MSVC_VERSION
779#pragma warning( pop )
784 static_cast<void>(j);
785 static_cast<void>(old_capacity);
830 template <
typename CompatibleType,
831 typename U = detail::uncvref_t<CompatibleType>,
832 detail::enable_if_t <
833 !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value,
int > = 0 >
835 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
836 std::forward<CompatibleType>(val))))
838 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
845 template <
typename BasicJsonType,
846 detail::enable_if_t <
847 detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value,
int > = 0 >
850 using other_boolean_t =
typename BasicJsonType::boolean_t;
851 using other_number_float_t =
typename BasicJsonType::number_float_t;
852 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
853 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
854 using other_string_t =
typename BasicJsonType::string_t;
855 using other_object_t =
typename BasicJsonType::object_t;
856 using other_array_t =
typename BasicJsonType::array_t;
857 using other_binary_t =
typename BasicJsonType::binary_t;
861 case value_t::boolean:
862 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
864 case value_t::number_float:
865 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
867 case value_t::number_integer:
868 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
870 case value_t::number_unsigned:
871 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
873 case value_t::string:
876 case value_t::object:
882 case value_t::binary:
888 case value_t::discarded:
889 m_data.m_type = value_t::discarded;
894 JSON_ASSERT(
m_data.m_type == val.type());
902 bool type_deduction =
true,
903 value_t manual_type = value_t::array)
907 bool is_an_object = std::all_of(init.begin(), init.end(),
908 [](
const detail::json_ref<basic_json>& element_ref)
913 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
920 if (manual_type == value_t::array)
922 is_an_object =
false;
928 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
nullptr));
935 m_data.m_type = value_t::object;
936 m_data.m_value = value_t::object;
938 for (
auto& element_ref : init)
940 auto element = element_ref.moved_or_copied();
941 m_data.m_value.object->emplace(
942 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
943 std::move((*element.m_data.m_value.array)[1]));
949 m_data.m_type = value_t::array;
950 m_data.m_value.array = create<array_t>(init.begin(), init.end());
963 res.m_data.m_type = value_t::binary;
964 res.m_data.m_value = init;
971 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
974 res.m_data.m_type = value_t::binary;
975 res.m_data.m_value =
binary_t(init, subtype);
985 res.m_data.m_type = value_t::binary;
986 res.m_data.m_value = std::move(init);
993 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
996 res.m_data.m_type = value_t::binary;
997 res.m_data.m_value =
binary_t(std::move(init), subtype);
1006 return basic_json(init,
false, value_t::array);
1014 return basic_json(init,
false, value_t::object);
1028 template <
class InputIT,
typename std::enable_if <
1029 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
1030 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >::type = 0 >
1033 JSON_ASSERT(first.m_object !=
nullptr);
1034 JSON_ASSERT(last.m_object !=
nullptr);
1039 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
1043 m_data.m_type = first.m_object->m_data.m_type;
1048 case value_t::boolean:
1049 case value_t::number_float:
1050 case value_t::number_integer:
1051 case value_t::number_unsigned:
1052 case value_t::string:
1055 || !last.m_it.primitive_iterator.is_end()))
1057 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", first.m_object));
1063 case value_t::object:
1064 case value_t::array:
1065 case value_t::binary:
1066 case value_t::discarded:
1073 case value_t::number_integer:
1075 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
1079 case value_t::number_unsigned:
1081 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
1085 case value_t::number_float:
1087 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
1091 case value_t::boolean:
1093 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
1097 case value_t::string:
1099 m_data.m_value = *first.m_object->m_data.m_value.string;
1103 case value_t::object:
1105 m_data.m_value.object = create<object_t>(first.m_it.object_iterator,
1106 last.m_it.object_iterator);
1110 case value_t::array:
1112 m_data.m_value.array = create<array_t>(first.m_it.array_iterator,
1113 last.m_it.array_iterator);
1117 case value_t::binary:
1119 m_data.m_value = *first.m_object->m_data.m_value.binary;
1124 case value_t::discarded:
1126 JSON_THROW(invalid_iterator::create(206, detail::concat(
"cannot construct with iterators from ", first.m_object->type_name()), first.m_object));
1137 template<
typename JsonRef,
1138 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
1139 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
1145 : json_base_class_t(other)
1147 m_data.m_type = other.m_data.m_type;
1149 other.assert_invariant();
1153 case value_t::object:
1155 m_data.m_value = *other.m_data.m_value.object;
1159 case value_t::array:
1161 m_data.m_value = *other.m_data.m_value.array;
1165 case value_t::string:
1167 m_data.m_value = *other.m_data.m_value.string;
1171 case value_t::boolean:
1173 m_data.m_value = other.m_data.m_value.boolean;
1177 case value_t::number_integer:
1179 m_data.m_value = other.m_data.m_value.number_integer;
1183 case value_t::number_unsigned:
1185 m_data.m_value = other.m_data.m_value.number_unsigned;
1189 case value_t::number_float:
1191 m_data.m_value = other.m_data.m_value.number_float;
1195 case value_t::binary:
1197 m_data.m_value = *other.m_data.m_value.binary;
1202 case value_t::discarded:
1214 : json_base_class_t(std::forward<json_base_class_t>(other)),
1215 m_data(std::move(other.m_data))
1218 other.assert_invariant(
false);
1221 other.m_data.m_type = value_t::null;
1222 other.m_data.m_value = {};
1231 std::is_nothrow_move_constructible<value_t>::value&&
1232 std::is_nothrow_move_assignable<value_t>::value&&
1233 std::is_nothrow_move_constructible<json_value>::value&&
1234 std::is_nothrow_move_assignable<json_value>::value&&
1235 std::is_nothrow_move_assignable<json_base_class_t>::value
1239 other.assert_invariant();
1242 swap(m_data.m_type, other.m_data.m_type);
1243 swap(m_data.m_value, other.m_data.m_value);
1244 json_base_class_t::operator=(std::move(other));
1255 assert_invariant(
false);
1272 const char indent_char =
' ',
1273 const bool ensure_ascii =
false,
1277 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
1281 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
1285 s.dump(*
this,
false, ensure_ascii, 0);
1291 void dump(raw_ostream& os,
const int indent = -1,
1292 const char indent_char =
' ',
1293 const bool ensure_ascii =
false,
1294 const error_handler_t error_handler = error_handler_t::strict)
const {
1299 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
1303 s.dump(*
this,
false, ensure_ascii, 0);
1313 return m_data.m_type;
1320 return is_null() || is_string() || is_boolean() || is_number() || is_binary();
1327 return is_array() || is_object();
1334 return m_data.m_type == value_t::null;
1341 return m_data.m_type == value_t::boolean;
1348 return is_number_integer() || is_number_float();
1355 return m_data.m_type == value_t::number_integer || m_data.m_type == value_t::number_unsigned;
1362 return m_data.m_type == value_t::number_unsigned;
1369 return m_data.m_type == value_t::number_float;
1376 return m_data.m_type == value_t::object;
1383 return m_data.m_type == value_t::array;
1390 return m_data.m_type == value_t::string;
1397 return m_data.m_type == value_t::binary;
1404 return m_data.m_type == value_t::discarded;
1411 return m_data.m_type;
1422 boolean_t get_impl(boolean_t* )
const
1426 return m_data.m_value.boolean;
1429 JSON_THROW(type_error::create(302, detail::concat(
"type must be boolean, but is ", type_name()),
this));
1433 object_t* get_impl_ptr(object_t* )
noexcept
1435 return is_object() ? m_data.m_value.object :
nullptr;
1439 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept
1441 return is_object() ? m_data.m_value.object :
nullptr;
1445 array_t* get_impl_ptr(array_t* )
noexcept
1447 return is_array() ? m_data.m_value.array :
nullptr;
1451 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
1453 return is_array() ? m_data.m_value.array :
nullptr;
1457 string_t* get_impl_ptr(string_t* )
noexcept
1459 return is_string() ? m_data.m_value.string :
nullptr;
1463 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept
1465 return is_string() ? m_data.m_value.string :
nullptr;
1469 boolean_t* get_impl_ptr(boolean_t* )
noexcept
1471 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
1475 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept
1477 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
1481 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept
1483 return is_number_integer() ? &m_data.m_value.number_integer :
nullptr;
1487 constexpr const number_integer_t* get_impl_ptr(
const number_integer_t* )
const noexcept
1489 return is_number_integer() ? &m_data.m_value.number_integer :
nullptr;
1493 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept
1495 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
1499 constexpr const number_unsigned_t* get_impl_ptr(
const number_unsigned_t* )
const noexcept
1501 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
1505 number_float_t* get_impl_ptr(number_float_t* )
noexcept
1507 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
1511 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept
1513 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
1517 binary_t* get_impl_ptr(binary_t* )
noexcept
1519 return is_binary() ? m_data.m_value.binary :
nullptr;
1523 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept
1525 return is_binary() ? m_data.m_value.binary :
nullptr;
1539 template<
typename ReferenceType,
typename ThisType>
1540 static ReferenceType get_ref_impl(ThisType& obj)
1543 auto*
ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
1550 JSON_THROW(type_error::create(303, detail::concat(
"incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj));
1560 template<
typename PointerType,
typename std::enable_if<
1561 std::is_pointer<PointerType>::value,
int>::type = 0>
1562 auto get_ptr() noexcept -> decltype(
std::declval<basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
1565 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
1570 template <
typename PointerType,
typename std::enable_if <
1571 std::is_pointer<PointerType>::value&&
1572 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int >::type = 0 >
1573 constexpr auto get_ptr() const noexcept -> decltype(
std::declval<const basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
1576 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
1611 template <
typename ValueType,
1612 detail::enable_if_t <
1613 detail::is_default_constructible<ValueType>::value&&
1614 detail::has_from_json<basic_json_t, ValueType>::value,
1616 ValueType get_impl(detail::priority_tag<0> )
const noexcept(
noexcept(
1617 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
1619 auto ret = ValueType();
1620 JSONSerializer<ValueType>::from_json(*
this, ret);
1654 template <
typename ValueType,
1655 detail::enable_if_t <
1656 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
1658 ValueType get_impl(detail::priority_tag<1> )
const noexcept(
noexcept(
1659 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
1661 return JSONSerializer<ValueType>::from_json(*
this);
1679 template <
typename BasicJsonType,
1680 detail::enable_if_t <
1681 detail::is_basic_json<BasicJsonType>::value,
1683 BasicJsonType get_impl(detail::priority_tag<2> )
const
1702 template<
typename BasicJsonType,
1703 detail::enable_if_t<
1704 std::is_same<BasicJsonType, basic_json_t>::value,
1706 basic_json get_impl(detail::priority_tag<3> )
const
1715 template<
typename PointerType,
1716 detail::enable_if_t<
1717 std::is_pointer<PointerType>::value,
1719 constexpr auto get_impl(detail::priority_tag<4> )
const noexcept
1720 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
1723 return get_ptr<PointerType>();
1750 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
1751#if defined(JSON_HAS_CPP_14)
1755 noexcept(
std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
1756 ->
decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))
1761 static_assert(!std::is_reference<ValueTypeCV>::value,
1762 "get() cannot be used with reference types, you might want to use get_ref()");
1763 return get_impl<ValueType>(detail::priority_tag<4> {});
1788 template<
typename PointerType,
typename std::enable_if<
1789 std::is_pointer<PointerType>::value,
int>::type = 0>
1790 auto get() noexcept -> decltype(
std::declval<basic_json_t&>().template get_ptr<PointerType>())
1793 return get_ptr<PointerType>();
1798 template <
typename ValueType,
1799 detail::enable_if_t <
1800 !detail::is_basic_json<ValueType>::value&&
1801 detail::has_from_json<basic_json_t, ValueType>::value,
1803 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
1804 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
1806 JSONSerializer<ValueType>::from_json(*
this, v);
1812 template<
typename ValueType,
1813 detail::enable_if_t <
1814 detail::is_basic_json<ValueType>::value,
1823 typename T, std::size_t N,
1824 typename Array = T (&)[N],
1825 detail::enable_if_t <
1826 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
1828 noexcept(
noexcept(JSONSerializer<Array>::from_json(
1829 std::declval<const basic_json_t&>(), v)))
1831 JSONSerializer<Array>::from_json(*
this, v);
1837 template<
typename ReferenceType,
typename std::enable_if<
1838 std::is_reference<ReferenceType>::value,
int>::type = 0>
1842 return get_ref_impl<ReferenceType>(*
this);
1847 template <
typename ReferenceType,
typename std::enable_if <
1848 std::is_reference<ReferenceType>::value&&
1849 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int >::type = 0 >
1853 return get_ref_impl<ReferenceType>(*
this);
1878 template <
typename ValueType,
typename std::enable_if <
1879 detail::conjunction <
1880 detail::negation<std::is_pointer<ValueType>>,
1881 detail::negation<std::is_same<ValueType, std::nullptr_t>>,
1882 detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>,
1883 detail::negation<std::is_same<ValueType, typename string_t::value_type>>,
1884 detail::negation<detail::is_basic_json<ValueType>>,
1885 detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>,
1886#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
1887 detail::negation<std::is_same<ValueType, std::string_view>>,
1889#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
1890 detail::negation<std::is_same<ValueType, std::any>>,
1892 detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
1893 >::value,
int >::type = 0 >
1894 JSON_EXPLICIT
operator ValueType()
const
1906 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
1909 return *get_ptr<binary_t*>();
1918 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
1921 return *get_ptr<const binary_t*>();
1943 return set_parent(m_data.m_value.array->at(idx));
1945 JSON_CATCH (std::out_of_range&)
1948 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
1953 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
1966 return m_data.m_value.array->at(idx);
1968 JSON_CATCH (std::out_of_range&)
1971 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
1976 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
1987 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
1990 auto it = m_data.
m_value.object->find(key);
1991 if (it == m_data.m_value.object->end())
1993 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
1995 return set_parent(it->second);
2000 template<
class KeyType, detail::enable_if_t<
2001 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2007 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
2010 auto it = m_data.
m_value.object->find(std::forward<KeyType>(key));
2011 if (it == m_data.m_value.object->end())
2013 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
2015 return set_parent(it->second);
2025 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
2028 auto it = m_data.
m_value.object->find(key);
2029 if (it == m_data.m_value.object->end())
2031 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
2038 template<
class KeyType, detail::enable_if_t<
2039 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2045 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
2048 auto it = m_data.
m_value.object->find(std::forward<KeyType>(key));
2049 if (it == m_data.m_value.object->end())
2051 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
2063 m_data.m_type = value_t::array;
2064 m_data.m_value.array = create<array_t>();
2072 if (idx >= m_data.m_value.array->size())
2076 const auto old_size = m_data.m_value.array->size();
2077 const auto old_capacity = m_data.m_value.array->capacity();
2079 m_data.m_value.array->resize(idx + 1);
2090 set_parents(begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
2096 return m_data.m_value.array->operator[](idx);
2099 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
2109 return m_data.m_value.array->operator[](idx);
2112 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
2122 m_data.m_type = value_t::object;
2123 m_data.m_value.object = create<object_t>();
2130 auto result = m_data.m_value.object->emplace(std::move(key),
nullptr);
2131 return set_parent(result.first->second);
2134 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
2144 auto it = m_data.m_value.object->find(key);
2145 JSON_ASSERT(it != m_data.m_value.object->end());
2149 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
2154 template<
typename T>
2157 return operator[](
typename object_t::key_type(key));
2160 template<
typename T>
2163 return operator[](
typename object_t::key_type(key));
2168 template<
class KeyType, detail::enable_if_t<
2169 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
2175 m_data.m_type = value_t::object;
2176 m_data.m_value.object = create<object_t>();
2183 auto result = m_data.m_value.object->emplace(std::forward<KeyType>(key),
nullptr);
2184 return set_parent(result.first->second);
2187 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
2192 template<
class KeyType, detail::enable_if_t<
2193 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
2199 auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
2200 JSON_ASSERT(it != m_data.m_value.object->end());
2204 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
2208 template<
typename KeyType>
2209 using is_comparable_with_object_key = detail::is_comparable <
2210 object_comparator_t,
const typename object_t::key_type&, KeyType >;
2212 template<
typename ValueType>
2213 using value_return_type = std::conditional <
2214 detail::is_c_string_uncvref<ValueType>::value,
2215 string_t,
typename std::decay<ValueType>::type >;
2220 template <
class ValueType, detail::enable_if_t <
2221 !detail::is_transparent<object_comparator_t>::value
2222 && detail::is_getable<basic_json_t, ValueType>::value
2223 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2224 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
2230 const auto it = find(key);
2236 return default_value;
2239 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
2244 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
2245 detail::enable_if_t <
2246 !detail::is_transparent<object_comparator_t>::value
2247 && detail::is_getable<basic_json_t, ReturnType>::value
2248 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2249 ReturnType
value(
const typename object_t::key_type& key, ValueType && default_value)
const
2255 const auto it = find(key);
2261 return std::forward<ValueType>(default_value);
2264 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
2269 template <
class ValueType,
class KeyType, detail::enable_if_t <
2270 detail::is_transparent<object_comparator_t>::value
2271 && !detail::is_json_pointer<KeyType>::value
2272 && is_comparable_with_object_key<KeyType>::value
2273 && detail::is_getable<basic_json_t, ValueType>::value
2274 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2275 ValueType
value(KeyType && key,
const ValueType& default_value)
const
2281 const auto it = find(std::forward<KeyType>(key));
2287 return default_value;
2290 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
2295 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
2296 detail::enable_if_t <
2297 detail::is_transparent<object_comparator_t>::value
2298 && !detail::is_json_pointer<KeyType>::value
2299 && is_comparable_with_object_key<KeyType>::value
2300 && detail::is_getable<basic_json_t, ReturnType>::value
2301 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2302 ReturnType
value(KeyType && key, ValueType && default_value)
const
2308 const auto it = find(std::forward<KeyType>(key));
2314 return std::forward<ValueType>(default_value);
2317 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
2322 template <
class ValueType, detail::enable_if_t <
2323 detail::is_getable<basic_json_t, ValueType>::value
2324 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2337 return default_value;
2341 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
2346 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
2347 detail::enable_if_t <
2348 detail::is_getable<basic_json_t, ReturnType>::value
2349 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2362 return std::forward<ValueType>(default_value);
2366 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
2369 template <
class ValueType,
class BasicJsonType, detail::enable_if_t <
2370 detail::is_basic_json<BasicJsonType>::value
2371 && detail::is_getable<basic_json_t, ValueType>::value
2372 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2376 return value(
ptr.convert(), default_value);
2379 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
2380 detail::enable_if_t <
2381 detail::is_basic_json<BasicJsonType>::value
2382 && detail::is_getable<basic_json_t, ReturnType>::value
2383 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2387 return value(
ptr.convert(), std::forward<ValueType>(default_value));
2424 template <
class IteratorType, detail::enable_if_t <
2425 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
2426 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
2432 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
2435 IteratorType result = end();
2437 switch (m_data.m_type)
2439 case value_t::boolean:
2440 case value_t::number_float:
2441 case value_t::number_integer:
2442 case value_t::number_unsigned:
2443 case value_t::string:
2444 case value_t::binary:
2448 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
2453 AllocatorType<string_t> alloc;
2454 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
2455 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
2456 m_data.m_value.string =
nullptr;
2458 else if (is_binary())
2460 AllocatorType<binary_t> alloc;
2461 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
2462 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
2463 m_data.m_value.binary =
nullptr;
2466 m_data.m_type = value_t::null;
2471 case value_t::object:
2473 result.m_it.object_iterator = m_data.m_value.object->erase(pos.m_it.object_iterator);
2477 case value_t::array:
2479 result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator);
2484 case value_t::discarded:
2486 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
2494 template <
class IteratorType, detail::enable_if_t <
2495 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
2496 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
2497 IteratorType
erase(IteratorType first, IteratorType last)
2502 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
2505 IteratorType result = end();
2507 switch (m_data.m_type)
2509 case value_t::boolean:
2510 case value_t::number_float:
2511 case value_t::number_integer:
2512 case value_t::number_unsigned:
2513 case value_t::string:
2514 case value_t::binary:
2517 || !last.m_it.primitive_iterator.is_end()))
2519 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
2524 AllocatorType<string_t> alloc;
2525 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
2526 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
2527 m_data.m_value.string =
nullptr;
2529 else if (is_binary())
2531 AllocatorType<binary_t> alloc;
2532 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
2533 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
2534 m_data.m_value.binary =
nullptr;
2537 m_data.m_type = value_t::null;
2542 case value_t::object:
2544 result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator,
2545 last.m_it.object_iterator);
2549 case value_t::array:
2551 result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator,
2552 last.m_it.array_iterator);
2557 case value_t::discarded:
2559 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
2566 template <
typename KeyType, detail::enable_if_t <
2567 detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
2568 size_type erase_internal(KeyType && key)
2573 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
2576 return m_data.m_value.object->erase(std::forward<KeyType>(key));
2579 template <
typename KeyType, detail::enable_if_t <
2580 !detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
2581 size_type erase_internal(KeyType && key)
2586 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
2589 const auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
2590 if (it != m_data.m_value.object->end())
2592 m_data.m_value.object->erase(it);
2606 return erase_internal(key);
2611 template<
class KeyType, detail::enable_if_t<
2612 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2615 return erase_internal(std::forward<KeyType>(key));
2627 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
2630 m_data.m_value.array->erase(m_data.m_value.array->begin() +
static_cast<difference_type>(idx));
2634 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
2651 auto result = end();
2655 result.m_it.object_iterator = m_data.m_value.object->find(key);
2665 auto result = cend();
2669 result.m_it.object_iterator = m_data.m_value.object->find(key);
2677 template<
class KeyType, detail::enable_if_t<
2678 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2681 auto result = end();
2685 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key));
2693 template<
class KeyType, detail::enable_if_t<
2694 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2697 auto result = cend();
2701 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key));
2712 return is_object() ? m_data.m_value.object->count(key) : 0;
2717 template<
class KeyType, detail::enable_if_t<
2718 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2722 return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(key)) : 0;
2727 bool contains(
const typename object_t::key_type& key)
const
2729 return is_object() && m_data.m_value.object->find(key) != m_data.m_value.object->end();
2734 template<
class KeyType, detail::enable_if_t<
2735 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2738 return is_object() && m_data.m_value.object->find(std::forward<KeyType>(key)) != m_data.m_value.object->end();
2745 return ptr.contains(
this);
2748 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
2752 return ptr.contains(
this);
2881 iteration_proxy<iterator>
items() noexcept
2883 return iteration_proxy<iterator>(*
this);
2888 iteration_proxy<const_iterator>
items() const noexcept
2890 return iteration_proxy<const_iterator>(*
this);
2906 switch (m_data.m_type)
2914 case value_t::array:
2917 return m_data.m_value.array->empty();
2920 case value_t::object:
2923 return m_data.m_value.object->empty();
2926 case value_t::string:
2927 case value_t::boolean:
2928 case value_t::number_integer:
2929 case value_t::number_unsigned:
2930 case value_t::number_float:
2931 case value_t::binary:
2932 case value_t::discarded:
2945 switch (m_data.m_type)
2953 case value_t::array:
2956 return m_data.m_value.array->size();
2959 case value_t::object:
2962 return m_data.m_value.object->size();
2965 case value_t::string:
2966 case value_t::boolean:
2967 case value_t::number_integer:
2968 case value_t::number_unsigned:
2969 case value_t::number_float:
2970 case value_t::binary:
2971 case value_t::discarded:
2984 switch (m_data.m_type)
2986 case value_t::array:
2989 return m_data.m_value.array->max_size();
2992 case value_t::object:
2995 return m_data.m_value.object->max_size();
2999 case value_t::string:
3000 case value_t::boolean:
3001 case value_t::number_integer:
3002 case value_t::number_unsigned:
3003 case value_t::number_float:
3004 case value_t::binary:
3005 case value_t::discarded:
3027 switch (m_data.m_type)
3029 case value_t::number_integer:
3031 m_data.m_value.number_integer = 0;
3035 case value_t::number_unsigned:
3037 m_data.m_value.number_unsigned = 0;
3041 case value_t::number_float:
3043 m_data.m_value.number_float = 0.0;
3047 case value_t::boolean:
3049 m_data.m_value.boolean =
false;
3053 case value_t::string:
3055 m_data.m_value.string->clear();
3059 case value_t::binary:
3061 m_data.m_value.binary->clear();
3065 case value_t::array:
3067 m_data.m_value.array->clear();
3071 case value_t::object:
3073 m_data.m_value.object->clear();
3078 case value_t::discarded:
3091 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
3097 m_data.m_type = value_t::array;
3098 m_data.m_value = value_t::array;
3103 const auto old_capacity = m_data.m_value.array->capacity();
3104 m_data.m_value.array->push_back(std::move(val));
3105 set_parent(m_data.m_value.array->back(), old_capacity);
3113 push_back(std::move(val));
3124 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
3130 m_data.m_type = value_t::array;
3131 m_data.m_value = value_t::array;
3136 const auto old_capacity = m_data.m_value.array->capacity();
3137 m_data.m_value.array->push_back(val);
3138 set_parent(m_data.m_value.array->back(), old_capacity);
3156 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
3162 m_data.m_type = value_t::object;
3163 m_data.m_value = value_t::object;
3168 auto res = m_data.m_value.object->insert(val);
3169 set_parent(res.first->second);
3184 if (is_object() && init.size() == 2 && (*init.begin())->is_string())
3187 push_back(
typename object_t::value_type(
3188 std::move(key.
get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
3206 template<
class... Args>
3212 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace_back() with ", type_name()),
this));
3218 m_data.m_type = value_t::array;
3219 m_data.m_value = value_t::array;
3224 const auto old_capacity = m_data.
m_value.array->capacity();
3225 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
3226 return set_parent(m_data.m_value.array->back(), old_capacity);
3231 template<
class... Args>
3232 std::pair<iterator, bool>
emplace(Args&& ... args)
3237 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace() with ", type_name()),
this));
3243 m_data.m_type = value_t::object;
3244 m_data.m_value = value_t::object;
3249 auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);
3250 set_parent(res.first->second);
3254 it.m_it.object_iterator = res.first;
3257 return {it, res.second};
3263 template<
typename... Args>
3267 JSON_ASSERT(m_data.m_value.array !=
nullptr);
3269 auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator);
3270 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
3271 result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos;
3291 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
3295 return insert_iterator(pos, val);
3298 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
3305 return insert(pos, val);
3318 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
3322 return insert_iterator(pos, cnt, val);
3325 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
3335 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
3341 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
3347 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
3352 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
this));
3356 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
3366 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
3372 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
3376 return insert_iterator(pos, ilist.begin(), ilist.end());
3386 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
3392 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
3398 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects",
this));
3401 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
3408 update(j.
begin(), j.
end(), merge_objects);
3418 m_data.m_type = value_t::object;
3419 m_data.m_value.object = create<object_t>();
3425 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", type_name()),
this));
3431 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
3437 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", first.m_object->type_name()), first.m_object));
3440 for (
auto it = first; it != last; ++it)
3442 if (merge_objects && it.value().is_object())
3444 auto it2 = m_data.m_value.object->find(it.key());
3445 if (it2 != m_data.m_value.object->end())
3447 it2->second.update(it.value(),
true);
3451 m_data.m_value.object->operator[](it.key()) = it.value();
3453 m_data.m_value.object->operator[](it.key()).m_parent =
this;
3461 std::is_nothrow_move_constructible<value_t>::value&&
3462 std::is_nothrow_move_assignable<value_t>::value&&
3463 std::is_nothrow_move_constructible<json_value>::value&&
3464 std::is_nothrow_move_assignable<json_value>::value
3467 std::swap(m_data.m_type, other.m_data.m_type);
3468 std::swap(m_data.m_value, other.m_data.m_value);
3471 other.set_parents();
3478 std::is_nothrow_move_constructible<value_t>::value&&
3479 std::is_nothrow_move_assignable<value_t>::value&&
3480 std::is_nothrow_move_constructible<json_value>::value&&
3481 std::is_nothrow_move_assignable<json_value>::value
3495 swap(*(m_data.m_value.array), other);
3499 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(array_t&) with ", type_name()),
this));
3511 swap(*(m_data.m_value.object), other);
3515 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(object_t&) with ", type_name()),
this));
3527 swap(*(m_data.m_value.string), other);
3531 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(string_t&) with ", type_name()),
this));
3543 swap(*(m_data.m_value.binary), other);
3547 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t&) with ", type_name()),
this));
3553 void swap(
typename binary_t::container_type& other)
3559 swap(*(m_data.m_value.binary), other);
3563 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t::container_type&) with ", type_name()),
this));
3578#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
3579 const auto lhs_type = lhs.type(); \
3580 const auto rhs_type = rhs.type(); \
3582 if (lhs_type == rhs_type) \
3586 case value_t::array: \
3587 return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \
3589 case value_t::object: \
3590 return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \
3592 case value_t::null: \
3593 return (null_result); \
3595 case value_t::string: \
3596 return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \
3598 case value_t::boolean: \
3599 return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \
3601 case value_t::number_integer: \
3602 return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \
3604 case value_t::number_unsigned: \
3605 return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \
3607 case value_t::number_float: \
3608 return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \
3610 case value_t::binary: \
3611 return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \
3613 case value_t::discarded: \
3615 return (unordered_result); \
3618 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
3620 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \
3622 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
3624 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \
3626 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
3628 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \
3630 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
3632 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \
3634 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
3636 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \
3638 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
3640 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \
3642 else if(compares_unordered(lhs, rhs))\
3644 return (unordered_result);\
3647 return (default_result);
3649 JSON_PRIVATE_UNLESS_TESTED:
3662#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
3665 static_cast<void>(inverse);
3671 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept
3673 return compares_unordered(*
this, rhs, inverse);
3677#if JSON_HAS_THREE_WAY_COMPARISON
3680 bool operator==(const_reference rhs)
const noexcept
3683#pragma GCC diagnostic push
3684#pragma GCC diagnostic ignored "-Wfloat-equal"
3686 const_reference lhs = *
this;
3689#pragma GCC diagnostic pop
3695 template<
typename ScalarType>
3696 requires std::is_scalar_v<ScalarType>
3697 bool operator==(ScalarType rhs)
const noexcept
3704 bool operator!=(const_reference rhs)
const noexcept
3706 if (compares_unordered(rhs,
true))
3715 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
3717 const_reference lhs = *
this;
3721 std::partial_ordering::equivalent,
3722 std::partial_ordering::unordered,
3723 lhs_type <=> rhs_type)
3728 template<
typename ScalarType>
3729 requires std::is_scalar_v<ScalarType>
3730 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
3735#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
3742 bool operator<=(const_reference rhs)
const noexcept
3744 if (compares_unordered(rhs,
true))
3748 return !(rhs < *
this);
3753 template<
typename ScalarType>
3754 requires std::is_scalar_v<ScalarType>
3755 bool operator<=(ScalarType rhs)
const noexcept
3763 bool operator>=(const_reference rhs)
const noexcept
3765 if (compares_unordered(rhs,
true))
3769 return !(*
this < rhs);
3774 template<
typename ScalarType>
3775 requires std::is_scalar_v<ScalarType>
3776 bool operator>=(ScalarType rhs)
const noexcept
3784 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept
3787#pragma GCC diagnostic push
3788#pragma GCC diagnostic ignored "-Wfloat-equal"
3792#pragma GCC diagnostic pop
3798 template<
typename ScalarType,
typename std::enable_if<
3799 std::is_scalar<ScalarType>::value,
int>::type = 0>
3800 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept
3807 template<
typename ScalarType,
typename std::enable_if<
3808 std::is_scalar<ScalarType>::value,
int>::type = 0>
3809 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept
3816 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept
3818 if (compares_unordered(lhs, rhs,
true))
3822 return !(lhs == rhs);
3827 template<
typename ScalarType,
typename std::enable_if<
3828 std::is_scalar<ScalarType>::value,
int>::type = 0>
3829 friend bool operator!=(const_reference lhs, ScalarType rhs)
noexcept
3836 template<
typename ScalarType,
typename std::enable_if<
3837 std::is_scalar<ScalarType>::value,
int>::type = 0>
3838 friend bool operator!=(ScalarType lhs, const_reference rhs)
noexcept
3845 friend bool operator<(const_reference lhs, const_reference rhs)
noexcept
3855 template<
typename ScalarType,
typename std::enable_if<
3856 std::is_scalar<ScalarType>::value,
int>::type = 0>
3857 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept
3864 template<
typename ScalarType,
typename std::enable_if<
3865 std::is_scalar<ScalarType>::value,
int>::type = 0>
3866 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept
3873 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept
3875 if (compares_unordered(lhs, rhs,
true))
3879 return !(rhs < lhs);
3884 template<
typename ScalarType,
typename std::enable_if<
3885 std::is_scalar<ScalarType>::value,
int>::type = 0>
3886 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept
3893 template<
typename ScalarType,
typename std::enable_if<
3894 std::is_scalar<ScalarType>::value,
int>::type = 0>
3895 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept
3902 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept
3905 if (compares_unordered(lhs, rhs))
3909 return !(lhs <= rhs);
3914 template<
typename ScalarType,
typename std::enable_if<
3915 std::is_scalar<ScalarType>::value,
int>::type = 0>
3916 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept
3923 template<
typename ScalarType,
typename std::enable_if<
3924 std::is_scalar<ScalarType>::value,
int>::type = 0>
3925 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept
3932 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept
3934 if (compares_unordered(lhs, rhs,
true))
3938 return !(lhs < rhs);
3943 template<
typename ScalarType,
typename std::enable_if<
3944 std::is_scalar<ScalarType>::value,
int>::type = 0>
3945 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept
3952 template<
typename ScalarType,
typename std::enable_if<
3953 std::is_scalar<ScalarType>::value,
int>::type = 0>
3954 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept
3960#undef JSON_IMPLEMENT_OPERATOR
3976 const bool pretty_print = o.width() > 0;
3977 const auto indentation = pretty_print ? o.width() : 0;
3983 serializer s(detail::output_adapter<char>(o), o.fill());
3984 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
3995 friend std::ostream& operator>>(
const basic_json& j, std::ostream& o)
4017 template<
typename InputType>
4020 const parser_callback_t cb =
nullptr,
4021 const bool allow_exceptions =
true,
4022 const bool ignore_comments =
false)
4025 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
4031 template<
typename IteratorType>
4035 const parser_callback_t cb =
nullptr,
4036 const bool allow_exceptions =
true,
4037 const bool ignore_comments =
false)
4040 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
4046 static basic_json parse(detail::span_input_adapter&& i,
4047 const parser_callback_t cb =
nullptr,
4048 const bool allow_exceptions =
true,
4049 const bool ignore_comments =
false)
4052 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
4058 template<
typename InputType>
4059 static bool accept(InputType&& i,
4060 const bool ignore_comments =
false)
4062 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
4067 template<
typename IteratorType>
4068 static bool accept(IteratorType first, IteratorType last,
4069 const bool ignore_comments =
false)
4071 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
4076 static bool accept(detail::span_input_adapter&& i,
4077 const bool ignore_comments =
false)
4079 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
4084 template <
typename InputType,
typename SAX>
4086 static
bool sax_parse(InputType&& i, SAX* sax,
4088 const
bool strict = true,
4089 const
bool ignore_comments = false)
4091 auto ia = detail::input_adapter(std::forward<InputType>(i));
4092 return format == input_format_t::json
4093 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
4094 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia),
format).sax_parse(
format, sax, strict);
4099 template<
class IteratorType,
class SAX>
4101 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
4103 const
bool strict = true,
4104 const
bool ignore_comments = false)
4106 auto ia = detail::input_adapter(std::move(first), std::move(last));
4107 return format == input_format_t::json
4108 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
4109 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia),
format).sax_parse(
format, sax, strict);
4117 template <
typename SAX>
4120 static
bool sax_parse(
detail::span_input_adapter&& i, SAX* sax,
4122 const
bool strict = true,
4123 const
bool ignore_comments = false)
4126 return format == input_format_t::json
4128 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
4130 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia),
format).sax_parse(
format, sax, strict);
4142 return operator>>(i, j);
4149 parser(detail::input_adapter(i)).parse(
false, j);
4164 switch (m_data.m_type)
4168 case value_t::object:
4170 case value_t::array:
4172 case value_t::string:
4174 case value_t::boolean:
4176 case value_t::binary:
4178 case value_t::discarded:
4180 case value_t::number_integer:
4181 case value_t::number_unsigned:
4182 case value_t::number_float:
4188 JSON_PRIVATE_UNLESS_TESTED:
4196 value_t m_type = value_t::null;
4199 json_value m_value = {};
4202 : m_type(v), m_value(v)
4209 m_value.array = create<array_t>(cnt, val);
4213 data(data&&) noexcept = default;
4214 data(const data&) noexcept = delete;
4215 data& operator=(data&&) noexcept = delete;
4216 data& operator=(const data&) noexcept = delete;
4220 m_value.destroy(m_type);
4243 std::vector<std::uint8_t> result;
4252 binary_writer<std::uint8_t>(o).write_cbor(j);
4259 binary_writer<char>(o).write_cbor(j);
4266 std::vector<std::uint8_t> result;
4267 to_msgpack(j, result);
4275 binary_writer<std::uint8_t>(o).write_msgpack(j);
4282 binary_writer<char>(o).write_msgpack(j);
4288 const bool use_size =
false,
4289 const bool use_type =
false)
4291 std::vector<std::uint8_t> result;
4292 to_ubjson(j, result, use_size, use_type);
4299 const bool use_size =
false,
const bool use_type =
false)
4301 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
4307 const bool use_size =
false,
const bool use_type =
false)
4309 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
4315 const bool use_size =
false,
4316 const bool use_type =
false)
4318 std::vector<std::uint8_t> result;
4319 to_bjdata(j, result, use_size, use_type);
4326 const bool use_size =
false,
const bool use_type =
false)
4328 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true);
4334 const bool use_size =
false,
const bool use_type =
false)
4336 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true);
4343 std::vector<std::uint8_t> result;
4352 binary_writer<std::uint8_t>(o).write_bson(j);
4359 binary_writer<char>(o).write_bson(j);
4364 template<
typename InputType>
4367 const bool strict =
true,
4368 const bool allow_exceptions =
true,
4372 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4373 auto ia = detail::input_adapter(std::forward<InputType>(i));
4374 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4375 return res ? result :
basic_json(value_t::discarded);
4380 template<
typename IteratorType>
4383 const bool strict =
true,
4384 const bool allow_exceptions =
true,
4388 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4389 auto ia = detail::input_adapter(std::move(first), std::move(last));
4390 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4391 return res ? result :
basic_json(value_t::discarded);
4394 template<
typename T>
4398 const
bool strict = true,
4399 const
bool allow_exceptions = true,
4402 return from_cbor(
ptr,
ptr + len, strict, allow_exceptions, tag_handler);
4408 const
bool strict = true,
4409 const
bool allow_exceptions = true,
4413 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4416 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4417 return res ? result :
basic_json(value_t::discarded);
4422 template<
typename InputType>
4425 const bool strict =
true,
4426 const bool allow_exceptions =
true)
4429 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4430 auto ia = detail::input_adapter(std::forward<InputType>(i));
4431 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4432 return res ? result :
basic_json(value_t::discarded);
4437 template<
typename IteratorType>
4440 const bool strict =
true,
4441 const bool allow_exceptions =
true)
4444 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4445 auto ia = detail::input_adapter(std::move(first), std::move(last));
4446 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4447 return res ? result :
basic_json(value_t::discarded);
4450 template<
typename T>
4454 const
bool strict = true,
4455 const
bool allow_exceptions = true)
4457 return from_msgpack(
ptr,
ptr + len, strict, allow_exceptions);
4463 const
bool strict = true,
4464 const
bool allow_exceptions = true)
4467 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4470 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4471 return res ? result :
basic_json(value_t::discarded);
4476 template<
typename InputType>
4479 const bool strict =
true,
4480 const bool allow_exceptions =
true)
4483 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4484 auto ia = detail::input_adapter(std::forward<InputType>(i));
4485 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4486 return res ? result :
basic_json(value_t::discarded);
4491 template<
typename IteratorType>
4494 const bool strict =
true,
4495 const bool allow_exceptions =
true)
4498 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4499 auto ia = detail::input_adapter(std::move(first), std::move(last));
4500 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4501 return res ? result :
basic_json(value_t::discarded);
4504 template<
typename T>
4508 const
bool strict = true,
4509 const
bool allow_exceptions = true)
4511 return from_ubjson(
ptr,
ptr + len, strict, allow_exceptions);
4517 const
bool strict = true,
4518 const
bool allow_exceptions = true)
4521 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4524 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4525 return res ? result :
basic_json(value_t::discarded);
4530 template<
typename InputType>
4533 const bool strict =
true,
4534 const bool allow_exceptions =
true)
4537 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4538 auto ia = detail::input_adapter(std::forward<InputType>(i));
4539 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
4540 return res ? result :
basic_json(value_t::discarded);
4545 template<
typename IteratorType>
4548 const bool strict =
true,
4549 const bool allow_exceptions =
true)
4552 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4553 auto ia = detail::input_adapter(std::move(first), std::move(last));
4554 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
4555 return res ? result :
basic_json(value_t::discarded);
4560 template<
typename InputType>
4563 const bool strict =
true,
4564 const bool allow_exceptions =
true)
4567 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4568 auto ia = detail::input_adapter(std::forward<InputType>(i));
4569 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4570 return res ? result :
basic_json(value_t::discarded);
4575 template<
typename IteratorType>
4578 const bool strict =
true,
4579 const bool allow_exceptions =
true)
4582 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4583 auto ia = detail::input_adapter(std::move(first), std::move(last));
4584 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4585 return res ? result :
basic_json(value_t::discarded);
4588 template<
typename T>
4592 const
bool strict = true,
4593 const
bool allow_exceptions = true)
4595 return from_bson(
ptr,
ptr + len, strict, allow_exceptions);
4601 const
bool strict = true,
4602 const
bool allow_exceptions = true)
4605 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
4608 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4609 return res ? result :
basic_json(value_t::discarded);
4624 return ptr.get_unchecked(
this);
4627 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
4631 return ptr.get_unchecked(
this);
4638 return ptr.get_unchecked(
this);
4641 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
4645 return ptr.get_unchecked(
this);
4652 return ptr.get_checked(
this);
4655 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
4659 return ptr.get_checked(
this);
4666 return ptr.get_checked(
this);
4669 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
4673 return ptr.get_checked(
this);
4681 json_pointer::flatten(
"", *
this, result);
4689 return json_pointer::unflatten(*
this);
4707 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
4709 const auto get_op = [](
const std::string & op)
4713 return patch_operations::add;
4717 return patch_operations::remove;
4719 if (op ==
"replace")
4721 return patch_operations::replace;
4725 return patch_operations::move;
4729 return patch_operations::copy;
4733 return patch_operations::test;
4736 return patch_operations::invalid;
4751 if (top_pointer !=
ptr)
4753 result.at(top_pointer);
4757 const auto last_path =
ptr.back();
4762 switch (parent.
m_data.m_type)
4765 case value_t::object:
4768 parent[last_path] = val;
4772 case value_t::array:
4774 if (last_path ==
"-")
4781 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
4785 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"), &parent));
4795 case value_t::string:
4796 case value_t::boolean:
4797 case value_t::number_integer:
4798 case value_t::number_unsigned:
4799 case value_t::number_float:
4800 case value_t::binary:
4801 case value_t::discarded:
4811 const auto last_path =
ptr.back();
4819 auto it = parent.
find(last_path);
4826 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", last_path,
"' not found"),
this));
4832 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
4839 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
4843 for (
const auto& val : json_patch)
4846 const auto get_value = [&val](
const std::string & op,
4847 const std::string & member,
4851 auto it = val.m_data.m_value.object->find(member);
4854 const auto error_msg = (op ==
"op") ?
"operation" : detail::concat(
"operation '", op,
'\'');
4860 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have member '", member,
"'"), &val));
4867 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have string member '", member,
"'"), &val));
4877 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &val));
4887 case patch_operations::add:
4889 operation_add(
ptr, get_value(
"add",
"value",
false));
4893 case patch_operations::remove:
4895 operation_remove(
ptr);
4899 case patch_operations::replace:
4902 result.at(
ptr) = get_value(
"replace",
"value",
false);
4906 case patch_operations::move:
4908 const auto from_path = get_value(
"move",
"from",
true).template
get<std::string>();
4918 operation_remove(from_ptr);
4919 operation_add(
ptr, v);
4923 case patch_operations::copy:
4925 const auto from_path = get_value(
"copy",
"from",
true).template
get<std::string>();
4934 operation_add(
ptr, v);
4938 case patch_operations::test:
4940 bool success =
false;
4945 success = (result.at(
ptr) == get_value(
"test",
"value",
false));
4955 JSON_THROW(other_error::create(501, detail::concat(
"unsuccessful: ", val.dump()), &val));
4961 case patch_operations::invalid:
4966 JSON_THROW(parse_error::create(105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
4985 const std::string& path =
"")
5001 {
"op",
"replace"}, {
"path", path}, {
"value", target}
5008 case value_t::array:
5012 while (i <
source.size() && i < target.
size())
5015 auto temp_diff = diff(
source[i], target[i], detail::concat(path,
'/', std::to_string(i)));
5016 result.insert(result.end(), temp_diff.begin(), temp_diff.end());
5025 while (i <
source.size())
5029 result.insert(result.begin() + end_index,
object(
5032 {
"path", detail::concat(path,
'/', std::to_string(i))}
5038 while (i < target.
size())
5043 {
"path", detail::concat(path,
"/-")},
5044 {
"value", target[i]}
5052 case value_t::object:
5055 for (
auto it =
source.cbegin(); it !=
source.cend(); ++it)
5058 const auto path_key = detail::concat(path,
'/', detail::escape(it.key()));
5060 if (target.
find(it.key()) != target.
end())
5063 auto temp_diff = diff(it.value(), target[it.key()], path_key);
5064 result.insert(result.end(), temp_diff.begin(), temp_diff.end());
5069 result.push_back(
object(
5071 {
"op",
"remove"}, {
"path", path_key}
5077 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
5082 const auto path_key = detail::concat(path,
'/', detail::escape(it.key()));
5085 {
"op",
"add"}, {
"path", path_key},
5086 {
"value", it.value()}
5095 case value_t::string:
5096 case value_t::boolean:
5097 case value_t::number_integer:
5098 case value_t::number_unsigned:
5099 case value_t::number_float:
5100 case value_t::binary:
5101 case value_t::discarded:
5107 {
"op",
"replace"}, {
"path", path}, {
"value", target}
5134 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
5136 if (it.value().is_null())
5142 operator[](it.key()).merge_patch(it.value());
5148 *
this = apply_patch;
5157WPI_BASIC_JSON_TPL_DECLARATION
5165inline namespace json_literals
5171#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
5172 inline wpi::json
operator ""_json(
const char* s, std::size_t n)
5174 inline wpi::json
operator "" _json(
const char* s, std::size_t n)
5177 return wpi::json::parse(s, s + n);
5183#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
5194WPI_JSON_NAMESPACE_END
5205WPI_BASIC_JSON_TPL_DECLARATION
5206struct hash<
wpi::WPI_BASIC_JSON_TPL>
5210 return wpi::detail::hash(j);
5216struct less< ::wpi::detail::value_t>
5223 ::wpi::detail::value_t rhs)
const noexcept
5225#if JSON_HAS_THREE_WAY_COMPARISON
5226 return std::is_lt(lhs <=> rhs);
5228 return ::wpi::detail::operator<(lhs, rhs);
5234#ifndef JSON_HAS_CPP_20
5238WPI_BASIC_JSON_TPL_DECLARATION
5239inline void swap(wpi::WPI_BASIC_JSON_TPL& j1, wpi::WPI_BASIC_JSON_TPL& j2)
noexcept(
5240 is_nothrow_move_constructible<wpi::WPI_BASIC_JSON_TPL>::value&&
5241 is_nothrow_move_assignable<wpi::WPI_BASIC_JSON_TPL>::value)
5250#if JSON_USE_GLOBAL_UDLS
5251 #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
5252 using wpi::literals::json_literals::operator
""_json;
5253 using wpi::literals::json_literals::operator
""_json_pointer;
5255 using wpi::literals::json_literals::operator
"" _json;
5256 using wpi::literals::json_literals::operator
"" _json_pointer;
5260#include <wpi/detail/macro_unscope.h>
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or glfw and nanopb were modified for use in Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation source
Definition ThirdPartyNotices.txt:123
namespace for Niels Lohmann
Definition json.h:99
constexpr bool is_string() const noexcept
return whether value is a string
Definition json.h:1388
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.h:2602
detail::cbor_tag_handler_t cbor_tag_handler_t
how to treat CBOR tags
Definition json.h:171
reference operator[](KeyType &&key)
access specified object element
Definition json.h:2170
size_type size() const noexcept
returns the number of elements
Definition json.h:2943
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
Definition json.h:4382
static std::vector< std::uint8_t > to_bjdata(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.h:4314
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)
Definition json.h:1754
const_iterator end() const noexcept
returns an iterator to one past the last element
Definition json.h:2800
reference back()
access the last element
Definition json.h:2406
basic_json(CompatibleType &&val) noexcept(noexcept(//NOLINT(bugprone-forwarding-reference-overload, bugprone-exception-escape) JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value from compatible types
Definition json.h:834
detail::parse_error parse_error
Definition json.h:188
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.h:2816
detail::input_format_t input_format_t
Definition json.h:175
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
Definition json.h:4974
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition json.h:4162
const_reference front() const
access the first element
Definition json.h:2399
constexpr bool is_array() const noexcept
return whether value is an array
Definition json.h:1381
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.h:3460
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.h:2350
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.h:2719
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition json.h:229
static void to_bjdata(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.h:4333
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition json.h:1353
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition json.h:233
data(size_type cnt, const basic_json &val)
Definition json.h:4206
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BSON format
Definition json.h:4577
static void to_bjdata(const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.h:4325
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.h:4622
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition json.h:224
std::size_t size_type
a type to represent container sizes
Definition json.h:216
detail::type_error type_error
Definition json.h:190
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.h:1325
wpi::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition json.h:364
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.h:2194
detail::error_handler_t error_handler_t
how to treat decoding errors
Definition json.h:169
detail::invalid_iterator invalid_iterator
Definition json.h:189
void swap(binary_t &other)
exchanges the values
Definition json.h:3537
ReferenceType get_ref()
get a reference value (implicit)
Definition json.h:1839
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.h:2982
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.h:3406
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.h:1850
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.h:1402
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.h:3198
void push_back(basic_json &&val)
add an object to an array
Definition json.h:3086
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.h:2139
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.h:2888
void dump(raw_ostream &os, const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
Definition json.h:1291
const_reference back() const
access the last element
Definition json.h:2415
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.h:2497
reference operator+=(const basic_json &val)
add an object to an array
Definition json.h:3143
friend void swap(reference left, reference right) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.h:3477
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
Definition json.h:4478
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init, typename binary_t::subtype_type subtype)
explicitly create a binary array (with subtype)
Definition json.h:971
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.h:3310
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BSON format
Definition json.h:4562
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.h:239
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.h:2002
iterator end() noexcept
returns an iterator to one past the last element
Definition json.h:2791
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.h:1360
void update(const_iterator first, const_iterator last, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.h:3413
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.h:4341
detail::exception exception
Definition json.h:187
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
Definition json.h:2823
data m_data
Definition json.h:4224
void push_back(initializer_list_t init)
add an object to an object
Definition json.h:3182
::wpi::detail::serializer< basic_json > serializer
Definition json.h:161
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
Definition json.h:801
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.h:1012
ValueType & get_to(ValueType &v) const
Definition json.h:1816
static void to_msgpack(const basic_json &j, detail::output_adapter< char > o)
create a MessagePack serialization of a given JSON value
Definition json.h:4280
iterator begin() noexcept
returns an iterator to the first element
Definition json.h:2766
detail::parse_event_t parse_event_t
parser event types
Definition json.h:797
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.h:2249
const_iterator cend() const noexcept
returns an iterator to one past the last element
Definition json.h:2807
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bjdata(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BJData format
Definition json.h:4532
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.h:4664
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.h:982
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.h:822
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
Definition json.h:4366
basic_json flatten() const
return flattened JSON value
Definition json.h:4678
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
Definition json.h:4493
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.h:2613
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition json.h:340
friend struct detail::external_constructor
Definition json.h:101
ObjectType< StringType, basic_json, default_object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
Definition json.h:332
const binary_t & get_binary() const
get a binary value
Definition json.h:1914
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.h:3330
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
Definition json.h:4703
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.h:2302
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
Definition json.h:4984
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.h:4636
value_type & reference
the type of an element reference
Definition json.h:209
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition json.h:173
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.h:2736
static void to_cbor(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a CBOR serialization of a given JSON value
Definition json.h:4250
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
create a BSON serialization of a given JSON value
Definition json.h:4357
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
Definition json.h:2649
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
Definition json.h:960
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.h:2040
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.h:247
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.h:1019
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.h:2663
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.h:4241
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.h:2427
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.h:3283
NumberFloatType number_float_t
a type for a number (floating-point)
Definition json.h:360
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.h:2224
AllocatorType< basic_json > allocator_type
the allocator type
Definition json.h:219
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition json.h:222
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
Definition json.h:1271
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.h:5126
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
Definition json.h:1803
reference operator[](T *key)
Definition json.h:2155
::wpi::json_pointer< StringType > json_pointer
JSON Pointer, see json_pointer.
Definition json.h:165
reference at(size_type idx)
access specified array element with bounds checking
Definition json.h:1936
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.h:2679
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition json.h:1367
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.h:2830
static std::vector< std::uint8_t > to_ubjson(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.h:4287
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.h:4650
BooleanType boolean_t
a type for a boolean
Definition json.h:348
detail::value_t value_t
Definition json.h:163
std::less< StringType > default_object_comparator_t
default object key comparator type The actual object key comparator type (object_comparator_t) may be...
Definition json.h:327
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.h:3174
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition json.h:2782
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.h:2117
constexpr auto get_ptr() const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.h:1573
~basic_json() noexcept
destructor
Definition json.h:1253
detail::out_of_range out_of_range
Definition json.h:191
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition json.h:2851
basic_json(initializer_list_t init, bool type_deduction=true, value_t manual_type=value_t::array)
create a container (array or object) from an initializer list
Definition json.h:901
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.h:3553
binary_t & get_binary()
get a binary value
Definition json.h:1902
friend class ::wpi::detail::parser
Definition json.h:109
const_iterator begin() const noexcept
returns an iterator to the first element
Definition json.h:2775
constexpr bool is_number() const noexcept
return whether value is a number
Definition json.h:1346
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.h:3381
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition json.h:4424
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.h:1790
const_reference operator[](T *key) const
Definition json.h:2161
data(const value_t v)
Definition json.h:4201
reference operator[](size_type idx)
access specified array element
Definition json.h:2058
basic_json(const JsonRef &ref)
Definition json.h:1140
JSONSerializer< T, SFINAE > json_serializer
Definition json.h:167
basic_json & operator=(basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value &&std::is_nothrow_move_assignable< json_base_class_t >::value)
copy assignment
Definition json.h:1230
static void to_ubjson(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.h:4306
Array get_to(T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v)))
Definition json.h:1827
NumberIntegerType number_integer_t
a type for a number (integer)
Definition json.h:352
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.h:1562
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.h:2020
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition json.h:1395
void swap(object_t &other)
exchanges the values
Definition json.h:3505
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.h:4687
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.h:3361
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init, typename binary_t::subtype_type subtype)
explicitly create a binary array (with subtype)
Definition json.h:993
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.h:2881
bool empty() const noexcept
checks whether the container is empty.
Definition json.h:2904
void swap(array_t &other)
exchanges the values
Definition json.h:3489
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.h:2620
reference operator+=(basic_json &&val)
add an object to an array
Definition json.h:3111
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.h:2743
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.h:1311
reference emplace_back(Args &&... args)
add an object to an array
Definition json.h:3207
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.h:2325
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.h:1004
StringType string_t
a type for a string
Definition json.h:344
void push_back(const basic_json &val)
add an object to an array
Definition json.h:3119
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.h:2275
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.h:1982
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bjdata(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BJData format
Definition json.h:4547
json_value m_value
the value of the current element
Definition json.h:4199
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition json.h:2844
json_sax< basic_json > json_sax_t
SAX interface type, see wpi::json_sax.
Definition json.h:177
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition json.h:1339
size_type count(const typename object_t::key_type &key) const
returns the number of occurrences of a key in a JSON object
Definition json.h:2709
reference front()
access the first element
Definition json.h:2392
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.h:1318
constexpr bool is_null() const noexcept
return whether value is null
Definition json.h:1332
void clear() noexcept
clears the contents
Definition json.h:3025
static void to_ubjson(const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.h:4298
detail::other_error other_error
Definition json.h:192
basic_json(basic_json &&other) noexcept
move constructor
Definition json.h:1213
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition json.h:227
basic_json(const value_t v)
create an empty value with a given type
Definition json.h:814
const_reference operator[](size_type idx) const
access specified array element
Definition json.h:2104
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition json.h:214
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.h:3303
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
Definition json.h:2837
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition json.h:356
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition json.h:4147
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.h:4264
void swap(string_t &other)
exchanges the values
Definition json.h:3521
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.h:848
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition json.h:231
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.h:1959
detail::actual_object_comparator_t< basic_json > object_comparator_t
object key comparator type
Definition json.h:368
basic_json(const basic_json &other)
copy constructor
Definition json.h:1144
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.h:3151
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.h:3232
static void to_cbor(const basic_json &j, detail::output_adapter< char > o)
create a CBOR serialization of a given JSON value
Definition json.h:4257
constexpr bool is_object() const noexcept
return whether value is an object
Definition json.h:1374
static void to_msgpack(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a MessagePack serialization of a given JSON value
Definition json.h:4273
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition json.h:4439
iterator insert_iterator(const_iterator pos, Args &&... args)
Helper for insertion of an iterator.
Definition json.h:3264
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.h:1031
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.h:2727
static void to_bson(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a BSON serialization of a given JSON value
Definition json.h:4350
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.h:2695
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
Definition json_fwd.h:56
#define JSON_HEDLEY_WARN_UNUSED_RESULT
Definition hedley.h:1130
#define JSON_HEDLEY_LIKELY(expr)
Definition hedley.h:1395
#define JSON_HEDLEY_NON_NULL(...)
Definition hedley.h:1288
#define JSON_HEDLEY_RETURNS_NON_NULL
Definition hedley.h:1729
#define JSON_HEDLEY_UNLIKELY(expr)
Definition hedley.h:1396
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
Definition hedley.h:1078
constexpr T & get(wpi::array< T, N > &arr) noexcept
Definition array.h:66
WPI_BASIC_JSON_TPL_DECLARATION std::string to_string(const WPI_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition json.h:5158
#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result)
Definition json.h:3578
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
constexpr friend auto operator==(allocator, allocator) noexcept -> bool
Definition format.h:754
constexpr friend auto operator!=(allocator, allocator) noexcept -> bool
Definition format.h:757
InequalityConstraints operator<=(LHS &&lhs, RHS &&rhs)
Less-than-or-equal-to comparison operator that returns an inequality constraint for two Variables.
Definition variable.hpp:706
InequalityConstraints operator>=(LHS &&lhs, RHS &&rhs)
Greater-than-or-equal-to comparison operator that returns an inequality constraint for two Variables.
Definition variable.hpp:736
InequalityConstraints operator<(LHS &&lhs, RHS &&rhs)
Less-than comparison operator that returns an inequality constraint for two Variables.
Definition variable.hpp:691
InequalityConstraints operator>(LHS &&lhs, RHS &&rhs)
Greater-than comparison operator that returns an inequality constraint for two Variables.
Definition variable.hpp:721
Definition PointerIntPair.h:280
WPI_BASIC_JSON_TPL_DECLARATION void swap(wpi::WPI_BASIC_JSON_TPL &j1, wpi::WPI_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.h:5239
Definition ntcore_cpp.h:26
array(T, Ts...) -> array< T, 1+sizeof...(Ts)>
raw_ostream & operator<<(raw_ostream &OS, sys::TimePoint<> TP)
std::size_t operator()(const wpi::WPI_BASIC_JSON_TPL &j) const
Definition json.h:5208
bool operator()(::wpi::detail::value_t lhs, ::wpi::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.h:5222