18#ifndef INCLUDE_WPI_JSON_HPP_
19#define INCLUDE_WPI_JSON_HPP_
24#include <initializer_list>
36#include <wpi/util/detail/conversions/from_json.hpp>
37#include <wpi/util/detail/conversions/to_json.hpp>
38#include <wpi/util/detail/exceptions.hpp>
39#include <wpi/util/detail/hash.hpp>
40#include <wpi/util/detail/input/binary_reader.hpp>
41#include <wpi/util/detail/input/input_adapters.hpp>
42#include <wpi/util/detail/input/lexer.hpp>
43#include <wpi/util/detail/input/parser.hpp>
44#include <wpi/util/detail/iterators/internal_iterator.hpp>
45#include <wpi/util/detail/iterators/iter_impl.hpp>
46#include <wpi/util/detail/iterators/iteration_proxy.hpp>
47#include <wpi/util/detail/iterators/json_reverse_iterator.hpp>
48#include <wpi/util/detail/iterators/primitive_iterator.hpp>
49#include <wpi/util/detail/json_custom_base_class.hpp>
50#include <wpi/util/detail/json_pointer.hpp>
51#include <wpi/util/detail/json_ref.hpp>
52#include <wpi/util/detail/macro_scope.hpp>
53#include <wpi/util/detail/string_concat.hpp>
54#include <wpi/util/detail/string_escape.hpp>
55#include <wpi/util/detail/string_utils.hpp>
56#include <wpi/util/detail/meta/cpp_future.hpp>
57#include <wpi/util/detail/meta/type_traits.hpp>
58#include <wpi/util/detail/output/binary_writer.hpp>
59#include <wpi/util/detail/output/output_adapters.hpp>
60#include <wpi/util/detail/output/serializer.hpp>
61#include <wpi/util/detail/value_t.hpp>
65#if defined(JSON_HAS_CPP_17)
66 #if JSON_HAS_STATIC_RTTI
69 #include <string_view>
77WPI_JSON_NAMESPACE_BEGIN
97WPI_BASIC_JSON_TPL_DECLARATION
99 :
public ::wpi::util::detail::json_base_class<CustomBaseClass>
102 template<detail::value_t>
friend struct detail::external_constructor;
105 friend class ::wpi::util::json_pointer;
109 template<
typename BasicJsonType,
typename InputType>
110 friend class ::wpi::util::detail::parser;
111 friend ::wpi::util::detail::serializer<basic_json>;
112 template<
typename BasicJsonType>
113 friend class ::wpi::util::detail::iter_impl;
114 template<
typename BasicJsonType,
typename CharType>
115 friend class ::wpi::util::detail::binary_writer;
116 template<
typename BasicJsonType,
typename InputType,
typename SAX>
117 friend class ::wpi::util::detail::binary_reader;
118 template<
typename BasicJsonType,
typename InputAdapterType>
119 friend class ::wpi::util::detail::json_sax_dom_parser;
120 template<
typename BasicJsonType,
typename InputAdapterType>
121 friend class ::wpi::util::detail::json_sax_dom_callback_parser;
122 friend class ::wpi::util::detail::exception;
125 using basic_json_t = WPI_BASIC_JSON_TPL;
126 using json_base_class_t = ::wpi::util::detail::json_base_class<CustomBaseClass>;
128 JSON_PRIVATE_UNLESS_TESTED:
130 using lexer = ::wpi::util::detail::lexer_base<basic_json>;
132 template<
typename InputAdapterType>
133 static ::wpi::util::detail::parser<basic_json, InputAdapterType>
parser(
134 InputAdapterType adapter,
135 detail::parser_callback_t<basic_json>cb =
nullptr,
136 const bool allow_exceptions =
true,
137 const bool ignore_comments =
false
140 return ::wpi::util::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
141 std::move(cb), allow_exceptions, ignore_comments);
145 using primitive_iterator_t = ::wpi::util::detail::primitive_iterator_t;
146 template<
typename BasicJsonType>
147 using internal_iterator = ::wpi::util::detail::internal_iterator<BasicJsonType>;
148 template<
typename BasicJsonType>
149 using iter_impl = ::wpi::util::detail::iter_impl<BasicJsonType>;
150 template<
typename Iterator>
151 using iteration_proxy = ::wpi::util::detail::iteration_proxy<Iterator>;
152 template<
typename Base>
using json_reverse_iterator = ::wpi::util::detail::json_reverse_iterator<Base>;
154 template<
typename CharType>
155 using output_adapter_t = ::wpi::util::detail::output_adapter_t<CharType>;
157 template<
typename InputType>
158 using binary_reader = ::wpi::util::detail::binary_reader<basic_json, InputType>;
159 template<
typename CharType>
using binary_writer = ::wpi::util::detail::binary_writer<basic_json, CharType>;
162 using serializer = ::wpi::util::detail::serializer<basic_json>;
167 template<
typename T,
typename SFINAE>
225 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
227 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
254 result[
"copyright"] =
"(C) 2013-2025 Niels Lohmann";
255 result[
"name"] =
"JSON for Modern C++";
256 result[
"url"] =
"https://github.com/nlohmann/json";
257 result[
"version"][
"string"] =
258 detail::concat(std::to_string(WPI_JSON_VERSION_MAJOR),
'.',
259 std::to_string(WPI_JSON_VERSION_MINOR),
'.',
260 std::to_string(WPI_JSON_VERSION_PATCH));
261 result[
"version"][
"major"] = WPI_JSON_VERSION_MAJOR;
262 result[
"version"][
"minor"] = WPI_JSON_VERSION_MINOR;
263 result[
"version"][
"patch"] = WPI_JSON_VERSION_PATCH;
266 result[
"platform"] =
"win32";
267#elif defined __linux__
268 result[
"platform"] =
"linux";
269#elif defined __APPLE__
270 result[
"platform"] =
"apple";
271#elif defined __unix__
272 result[
"platform"] =
"unix";
274 result[
"platform"] =
"unknown";
277#if defined(__ICC) || defined(__INTEL_COMPILER)
278 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
279#elif defined(__clang__)
280 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
281#elif defined(__GNUC__) || defined(__GNUG__)
282 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", detail::concat(
283 std::to_string(__GNUC__),
'.',
284 std::to_string(__GNUC_MINOR__),
'.',
285 std::to_string(__GNUC_PATCHLEVEL__))
288#elif defined(__HP_cc) || defined(__HP_aCC)
289 result[
"compiler"] =
"hp"
290#elif defined(__IBMCPP__)
291 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
292#elif defined(_MSC_VER)
293 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
295 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
296#elif defined(__SUNPRO_CC)
297 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
299 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
302#if defined(_MSVC_LANG)
303 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
304#elif defined(__cplusplus)
305 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
307 result[
"compiler"][
"c++"] =
"unknown";
325#if defined(JSON_HAS_CPP_14)
338 AllocatorType<std::pair<
const StringType,
343 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
367 using binary_t = wpi::util::byte_container_with_subtype<BinaryType>;
378 template<
typename T,
typename... Args>
380 static T* create(Args&& ... args)
382 AllocatorType<T> alloc;
383 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
385 auto deleter = [&](T * obj)
387 AllocatorTraits::deallocate(alloc, obj, 1);
389 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
390 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
391 JSON_ASSERT(obj !=
nullptr);
392 return obj.release();
399 JSON_PRIVATE_UNLESS_TESTED:
445 json_value() =
default;
447 json_value(
boolean_t v) noexcept : boolean(v) {}
459 case value_t::object:
461 object = create<object_t>();
467 array = create<array_t>();
471 case value_t::string:
473 string = create<string_t>(
"");
477 case value_t::binary:
479 binary = create<binary_t>();
483 case value_t::boolean:
489 case value_t::number_integer:
495 case value_t::number_unsigned:
501 case value_t::number_float:
513 case value_t::discarded:
519 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.12.0",
nullptr));
559 (t == value_t::object &&
object ==
nullptr) ||
560 (t == value_t::array && array ==
nullptr) ||
561 (t == value_t::string &&
string ==
nullptr) ||
562 (t == value_t::binary && binary ==
nullptr)
568 if (t == value_t::array || t == value_t::object)
571 std::vector<basic_json> stack;
574 if (t == value_t::array)
576 stack.reserve(
array->size());
577 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
582 for (
auto&& it : *
object)
584 stack.push_back(std::move(it.second));
588 while (!stack.empty())
591 basic_json current_item(std::move(stack.back()));
596 if (current_item.is_array())
598 std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));
600 current_item.m_data.m_value.array->clear();
602 else if (current_item.is_object())
604 for (
auto&& it : *current_item.m_data.m_value.object)
606 stack.push_back(std::move(it.second));
609 current_item.m_data.m_value.object->clear();
619 case value_t::object:
621 AllocatorType<object_t> alloc;
622 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
623 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
629 AllocatorType<array_t> alloc;
630 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
631 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
635 case value_t::string:
637 AllocatorType<string_t> alloc;
638 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
639 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
643 case value_t::binary:
645 AllocatorType<binary_t> alloc;
646 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
647 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
652 case value_t::boolean:
653 case value_t::number_integer:
654 case value_t::number_unsigned:
655 case value_t::number_float:
656 case value_t::discarded:
684 void assert_invariant(
bool check_parents =
true) const noexcept
686 JSON_ASSERT(
m_data.m_type != value_t::object ||
m_data.m_value.object !=
nullptr);
687 JSON_ASSERT(
m_data.m_type != value_t::array ||
m_data.m_value.array !=
nullptr);
688 JSON_ASSERT(
m_data.m_type != value_t::string ||
m_data.m_value.string !=
nullptr);
689 JSON_ASSERT(
m_data.m_type != value_t::binary ||
m_data.m_value.binary !=
nullptr);
697 return j.m_parent ==
this;
702 static_cast<void>(check_parents);
712 for (
auto& element : *
m_data.m_value.array)
714 element.m_parent =
this;
719 case value_t::object:
721 for (
auto& element : *
m_data.m_value.object)
723 element.second.m_parent =
this;
729 case value_t::string:
730 case value_t::boolean:
731 case value_t::number_integer:
732 case value_t::number_unsigned:
733 case value_t::number_float:
734 case value_t::binary:
735 case value_t::discarded:
742 iterator set_parents(
iterator it,
typename iterator::difference_type count_set_parents)
745 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
747 (it + i)->m_parent =
this;
750 static_cast<void>(count_set_parents);
758 if (old_capacity != detail::unknown_size())
761 JSON_ASSERT(
type() == value_t::array);
772#ifdef JSON_HEDLEY_MSVC_VERSION
773#pragma warning(push )
774#pragma warning(disable : 4127)
776 if (detail::is_ordered_map<object_t>::value)
781#ifdef JSON_HEDLEY_MSVC_VERSION
782#pragma warning( pop )
787 static_cast<void>(j);
788 static_cast<void>(old_capacity);
833 template <
typename CompatibleType,
834 typename U = detail::uncvref_t<CompatibleType>,
835 detail::enable_if_t <
836 !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value,
int > = 0 >
838 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
839 std::forward<CompatibleType>(val))))
841 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
848 template <
typename BasicJsonType,
849 detail::enable_if_t <
850 detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value,
int > = 0 >
852#if JSON_DIAGNOSTIC_POSITIONS
853 : start_position(val.start_pos()),
854 end_position(val.end_pos())
857 using other_boolean_t =
typename BasicJsonType::boolean_t;
858 using other_number_float_t =
typename BasicJsonType::number_float_t;
859 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
860 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
861 using other_string_t =
typename BasicJsonType::string_t;
862 using other_object_t =
typename BasicJsonType::object_t;
863 using other_array_t =
typename BasicJsonType::array_t;
864 using other_binary_t =
typename BasicJsonType::binary_t;
868 case value_t::boolean:
871 case value_t::number_float:
874 case value_t::number_integer:
877 case value_t::number_unsigned:
880 case value_t::string:
883 case value_t::object:
889 case value_t::binary:
895 case value_t::discarded:
896 m_data.m_type = value_t::discarded;
901 JSON_ASSERT(
m_data.m_type == val.type());
910 bool type_deduction =
true,
911 value_t manual_type = value_t::array)
915 bool is_an_object = std::all_of(init.begin(), init.end(),
916 [](
const detail::json_ref<basic_json>& element_ref)
921 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
928 if (manual_type == value_t::array)
930 is_an_object =
false;
936 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
nullptr));
943 m_data.m_type = value_t::object;
944 m_data.m_value = value_t::object;
946 for (
auto& element_ref : init)
948 auto element = element_ref.moved_or_copied();
949 m_data.m_value.object->emplace(
950 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
951 std::move((*element.m_data.m_value.array)[1]));
957 m_data.m_type = value_t::array;
958 m_data.m_value.array = create<array_t>(init.begin(), init.end());
971 res.m_data.m_type = value_t::binary;
972 res.m_data.m_value = init;
979 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
982 res.m_data.m_type = value_t::binary;
983 res.m_data.m_value =
binary_t(init, subtype);
993 res.m_data.m_type = value_t::binary;
994 res.m_data.m_value = std::move(init);
1001 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
1004 res.m_data.m_type = value_t::binary;
1005 res.m_data.m_value =
binary_t(std::move(init), subtype);
1014 return basic_json(init,
false, value_t::array);
1022 return basic_json(init,
false, value_t::object);
1036 template <
class InputIT,
typename std::enable_if <
1037 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
1038 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
1041 JSON_ASSERT(first.m_object !=
nullptr);
1042 JSON_ASSERT(last.m_object !=
nullptr);
1047 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
1051 m_data.m_type = first.m_object->m_data.m_type;
1056 case value_t::boolean:
1057 case value_t::number_float:
1058 case value_t::number_integer:
1059 case value_t::number_unsigned:
1060 case value_t::string:
1063 || !last.m_it.primitive_iterator.is_end()))
1065 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", first.m_object));
1071 case value_t::object:
1072 case value_t::array:
1073 case value_t::binary:
1074 case value_t::discarded:
1081 case value_t::number_integer:
1083 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
1087 case value_t::number_unsigned:
1089 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
1093 case value_t::number_float:
1095 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
1099 case value_t::boolean:
1101 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
1105 case value_t::string:
1107 m_data.m_value = *first.m_object->m_data.m_value.string;
1111 case value_t::object:
1113 m_data.m_value.object = create<object_t>(first.m_it.object_iterator,
1114 last.m_it.object_iterator);
1118 case value_t::array:
1120 m_data.m_value.array = create<array_t>(first.m_it.array_iterator,
1121 last.m_it.array_iterator);
1125 case value_t::binary:
1127 m_data.m_value = *first.m_object->m_data.m_value.binary;
1132 case value_t::discarded:
1134 JSON_THROW(invalid_iterator::create(206, detail::concat(
"cannot construct with iterators from ", first.m_object->type_name()), first.m_object));
1145 template<
typename JsonRef,
1146 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
1147 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
1153 : json_base_class_t(other)
1154#
if JSON_DIAGNOSTIC_POSITIONS
1155 , start_position(other.start_position)
1156 , end_position(other.end_position)
1161 other.assert_invariant();
1165 case value_t::object:
1167 m_data.m_value = *other.m_data.m_value.object;
1171 case value_t::array:
1173 m_data.m_value = *other.m_data.m_value.array;
1177 case value_t::string:
1179 m_data.m_value = *other.m_data.m_value.string;
1183 case value_t::boolean:
1185 m_data.m_value = other.m_data.m_value.boolean;
1189 case value_t::number_integer:
1191 m_data.m_value = other.m_data.m_value.number_integer;
1195 case value_t::number_unsigned:
1197 m_data.m_value = other.m_data.m_value.number_unsigned;
1201 case value_t::number_float:
1203 m_data.m_value = other.m_data.m_value.number_float;
1207 case value_t::binary:
1209 m_data.m_value = *other.m_data.m_value.binary;
1214 case value_t::discarded:
1226 : json_base_class_t(std::forward<json_base_class_t>(other)),
1227 m_data(std::move(other.m_data))
1228#if JSON_DIAGNOSTIC_POSITIONS
1229 , start_position(other.start_position)
1230 , end_position(other.end_position)
1234 other.assert_invariant(
false);
1237 other.m_data.m_type = value_t::null;
1238 other.m_data.m_value = {};
1240#if JSON_DIAGNOSTIC_POSITIONS
1241 other.start_position = std::string::npos;
1242 other.end_position = std::string::npos;
1252 std::is_nothrow_move_constructible<value_t>::value&&
1253 std::is_nothrow_move_assignable<value_t>::value&&
1254 std::is_nothrow_move_constructible<json_value>::value&&
1255 std::is_nothrow_move_assignable<json_value>::value&&
1256 std::is_nothrow_move_assignable<json_base_class_t>::value
1260 other.assert_invariant();
1266#if JSON_DIAGNOSTIC_POSITIONS
1267 swap(start_position, other.start_position);
1268 swap(end_position, other.end_position);
1271 json_base_class_t::operator=(std::move(other));
1282 assert_invariant(
false);
1299 const char indent_char =
' ',
1300 const bool ensure_ascii =
false,
1304 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
1308 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
1312 s.dump(*
this,
false, ensure_ascii, 0);
1318 void dump(raw_ostream& os,
const int indent = -1,
1319 const char indent_char =
' ',
1320 const bool ensure_ascii =
false,
1321 const error_handler_t error_handler = error_handler_t::strict)
const {
1326 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
1330 s.dump(*
this,
false, ensure_ascii, 0);
1361 return m_data.m_type == value_t::null;
1368 return m_data.m_type == value_t::boolean;
1382 return m_data.m_type == value_t::number_integer ||
m_data.m_type == value_t::number_unsigned;
1389 return m_data.m_type == value_t::number_unsigned;
1396 return m_data.m_type == value_t::number_float;
1403 return m_data.m_type == value_t::object;
1410 return m_data.m_type == value_t::array;
1417 return m_data.m_type == value_t::string;
1424 return m_data.m_type == value_t::binary;
1431 return m_data.m_type == value_t::discarded;
1449 boolean_t get_impl(boolean_t* )
const
1453 return m_data.m_value.boolean;
1456 JSON_THROW(type_error::create(302, detail::concat(
"type must be boolean, but is ", type_name()),
this));
1460 object_t* get_impl_ptr(object_t* )
noexcept
1462 return is_object() ? m_data.m_value.object :
nullptr;
1466 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept
1468 return is_object() ? m_data.m_value.object :
nullptr;
1472 array_t* get_impl_ptr(array_t* )
noexcept
1474 return is_array() ? m_data.m_value.array :
nullptr;
1478 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
1480 return is_array() ? m_data.m_value.array :
nullptr;
1484 string_t* get_impl_ptr(string_t* )
noexcept
1486 return is_string() ? m_data.m_value.string :
nullptr;
1490 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept
1492 return is_string() ? m_data.m_value.string :
nullptr;
1496 boolean_t* get_impl_ptr(boolean_t* )
noexcept
1498 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
1502 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept
1504 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
1508 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept
1510 return m_data.m_type == value_t::number_integer ? &m_data.m_value.number_integer :
nullptr;
1514 constexpr const number_integer_t* get_impl_ptr(
const number_integer_t* )
const noexcept
1516 return m_data.m_type == value_t::number_integer ? &m_data.m_value.number_integer :
nullptr;
1520 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept
1522 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
1526 constexpr const number_unsigned_t* get_impl_ptr(
const number_unsigned_t* )
const noexcept
1528 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
1532 number_float_t* get_impl_ptr(number_float_t* )
noexcept
1534 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
1538 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept
1540 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
1544 binary_t* get_impl_ptr(binary_t* )
noexcept
1546 return is_binary() ? m_data.m_value.binary :
nullptr;
1550 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept
1552 return is_binary() ? m_data.m_value.binary :
nullptr;
1566 template<
typename ReferenceType,
typename ThisType>
1567 static ReferenceType get_ref_impl(ThisType& obj)
1570 auto*
ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
1577 JSON_THROW(type_error::create(303, detail::concat(
"incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj));
1587 template<
typename PointerType,
typename std::enable_if<
1588 std::is_pointer<PointerType>::value,
int>::type = 0>
1589 auto get_ptr() noexcept -> decltype(
std::declval<basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
1592 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
1597 template <
typename PointerType,
typename std::enable_if <
1598 std::is_pointer<PointerType>::value&&
1599 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int >::type = 0 >
1600 constexpr auto get_ptr() const noexcept -> decltype(
std::declval<const basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
1603 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
1638 template <
typename ValueType,
1639 detail::enable_if_t <
1640 detail::is_default_constructible<ValueType>::value&&
1641 detail::has_from_json<basic_json_t, ValueType>::value,
1643 ValueType get_impl(detail::priority_tag<0> )
const noexcept(
noexcept(
1644 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
1646 auto ret = ValueType();
1647 JSONSerializer<ValueType>::from_json(*
this, ret);
1681 template <
typename ValueType,
1682 detail::enable_if_t <
1683 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
1685 ValueType get_impl(detail::priority_tag<1> )
const noexcept(
noexcept(
1686 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
1688 return JSONSerializer<ValueType>::from_json(*
this);
1706 template <
typename BasicJsonType,
1707 detail::enable_if_t <
1708 detail::is_basic_json<BasicJsonType>::value,
1710 BasicJsonType get_impl(detail::priority_tag<2> )
const
1729 template<
typename BasicJsonType,
1730 detail::enable_if_t<
1731 std::is_same<BasicJsonType, basic_json_t>::value,
1733 basic_json get_impl(detail::priority_tag<3> )
const
1742 template<
typename PointerType,
1743 detail::enable_if_t<
1744 std::is_pointer<PointerType>::value,
1746 constexpr auto get_impl(detail::priority_tag<4> )
const noexcept
1747 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
1750 return get_ptr<PointerType>();
1777 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
1778#if defined(JSON_HAS_CPP_14)
1782 noexcept(
std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
1783 ->
decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))
1788 static_assert(!std::is_reference<ValueTypeCV>::value,
1789 "get() cannot be used with reference types, you might want to use get_ref()");
1790 return get_impl<ValueType>(detail::priority_tag<4> {});
1815 template<
typename PointerType,
typename std::enable_if<
1816 std::is_pointer<PointerType>::value,
int>::type = 0>
1817 auto get() noexcept -> decltype(
std::declval<basic_json_t&>().template
get_ptr<PointerType>())
1825 template <
typename ValueType,
1826 detail::enable_if_t <
1827 !detail::is_basic_json<ValueType>::value&&
1828 detail::has_from_json<basic_json_t, ValueType>::value,
1830 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
1831 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
1833 JSONSerializer<ValueType>::from_json(*
this, v);
1839 template<
typename ValueType,
1840 detail::enable_if_t <
1841 detail::is_basic_json<ValueType>::value,
1850 typename T, std::size_t N,
1851 typename Array = T (&)[N],
1852 detail::enable_if_t <
1853 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
1855 noexcept(
noexcept(JSONSerializer<Array>::from_json(
1856 std::declval<const basic_json_t&>(), v)))
1858 JSONSerializer<Array>::from_json(*
this, v);
1864 template<
typename ReferenceType,
typename std::enable_if<
1865 std::is_reference<ReferenceType>::value,
int>::type = 0>
1869 return get_ref_impl<ReferenceType>(*
this);
1874 template <
typename ReferenceType,
typename std::enable_if <
1875 std::is_reference<ReferenceType>::value&&
1876 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int >::type = 0 >
1880 return get_ref_impl<ReferenceType>(*
this);
1905 template <
typename ValueType,
typename std::enable_if <
1906 detail::conjunction <
1907 detail::negation<std::is_pointer<ValueType>>,
1908 detail::negation<std::is_same<ValueType, std::nullptr_t>>,
1909 detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>,
1910 detail::negation<std::is_same<ValueType, typename string_t::value_type>>,
1911 detail::negation<detail::is_basic_json<ValueType>>,
1912 detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>,
1913#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
1914 detail::negation<std::is_same<ValueType, std::string_view>>,
1916#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
1917 detail::negation<std::is_same<ValueType, std::any>>,
1919 detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
1920 >::value,
int >::type = 0 >
1921 JSON_EXPLICIT
operator ValueType()
const
1933 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ",
type_name()),
this));
1945 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ",
type_name()),
this));
1970 return set_parent(
m_data.m_value.array->at(idx));
1972 JSON_CATCH (std::out_of_range&)
1975 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
1980 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
1993 return m_data.m_value.array->at(idx);
1995 JSON_CATCH (std::out_of_range&)
1998 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
2003 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
2014 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
2017 auto it =
m_data.m_value.object->find(key);
2018 if (it ==
m_data.m_value.object->end())
2020 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
2022 return set_parent(it->second);
2027 template<
class KeyType, detail::enable_if_t<
2028 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2034 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
2037 auto it =
m_data.m_value.object->find(std::forward<KeyType>(key));
2038 if (it ==
m_data.m_value.object->end())
2040 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
2042 return set_parent(it->second);
2052 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
2055 auto it =
m_data.m_value.object->find(key);
2056 if (it ==
m_data.m_value.object->end())
2058 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
2065 template<
class KeyType, detail::enable_if_t<
2066 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2072 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
2075 auto it =
m_data.m_value.object->find(std::forward<KeyType>(key));
2076 if (it ==
m_data.m_value.object->end())
2078 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
2090 m_data.m_type = value_t::array;
2091 m_data.m_value.array = create<array_t>();
2099 if (idx >=
m_data.m_value.array->size())
2103 const auto old_size =
m_data.m_value.array->size();
2104 const auto old_capacity =
m_data.m_value.array->capacity();
2106 m_data.m_value.array->resize(idx + 1);
2117 set_parents(
begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
2123 return m_data.m_value.array->operator[](idx);
2126 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ",
type_name()),
this));
2136 return m_data.m_value.array->operator[](idx);
2139 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ",
type_name()),
this));
2149 m_data.m_type = value_t::object;
2150 m_data.m_value.object = create<object_t>();
2157 auto result =
m_data.m_value.object->emplace(std::move(key),
nullptr);
2158 return set_parent(result.first->second);
2161 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
this));
2171 auto it =
m_data.m_value.object->find(key);
2172 JSON_ASSERT(it !=
m_data.m_value.object->end());
2176 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
this));
2181 template<
typename T>
2184 return operator[](
typename object_t::key_type(key));
2187 template<
typename T>
2190 return operator[](
typename object_t::key_type(key));
2195 template<
class KeyType, detail::enable_if_t<
2196 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
2202 m_data.m_type = value_t::object;
2203 m_data.m_value.object = create<object_t>();
2210 auto result =
m_data.m_value.object->emplace(std::forward<KeyType>(key),
nullptr);
2211 return set_parent(result.first->second);
2214 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
this));
2219 template<
class KeyType, detail::enable_if_t<
2220 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
2226 auto it =
m_data.m_value.object->find(std::forward<KeyType>(key));
2227 JSON_ASSERT(it !=
m_data.m_value.object->end());
2231 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
this));
2235 template<
typename KeyType>
2236 using is_comparable_with_object_key = detail::is_comparable <
2237 object_comparator_t,
const typename object_t::key_type&, KeyType >;
2239 template<
typename ValueType>
2240 using value_return_type = std::conditional <
2241 detail::is_c_string_uncvref<ValueType>::value,
2242 string_t,
typename std::decay<ValueType>::type >;
2247 template <
class ValueType, detail::enable_if_t <
2248 !detail::is_transparent<object_comparator_t>::value
2249 && detail::is_getable<basic_json_t, ValueType>::value
2250 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2251 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
2257 const auto it =
find(key);
2263 return default_value;
2266 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
2271 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
2272 detail::enable_if_t <
2273 !detail::is_transparent<object_comparator_t>::value
2274 && detail::is_getable<basic_json_t, ReturnType>::value
2275 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2276 ReturnType
value(
const typename object_t::key_type& key, ValueType && default_value)
const
2282 const auto it =
find(key);
2288 return std::forward<ValueType>(default_value);
2291 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
2296 template <
class ValueType,
class KeyType, 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, ValueType>::value
2301 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2302 ValueType
value(KeyType && key,
const ValueType& default_value)
const
2308 const auto it =
find(std::forward<KeyType>(key));
2314 return default_value;
2317 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
2322 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
2323 detail::enable_if_t <
2324 detail::is_transparent<object_comparator_t>::value
2325 && !detail::is_json_pointer<KeyType>::value
2326 && is_comparable_with_object_key<KeyType>::value
2327 && detail::is_getable<basic_json_t, ReturnType>::value
2328 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2329 ReturnType
value(KeyType && key, ValueType && default_value)
const
2335 const auto it =
find(std::forward<KeyType>(key));
2341 return std::forward<ValueType>(default_value);
2344 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
2349 template <
class ValueType, detail::enable_if_t <
2350 detail::is_getable<basic_json_t, ValueType>::value
2351 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2364 return default_value;
2368 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
2373 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
2374 detail::enable_if_t <
2375 detail::is_getable<basic_json_t, ReturnType>::value
2376 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2389 return std::forward<ValueType>(default_value);
2393 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
2396 template <
class ValueType,
class BasicJsonType, detail::enable_if_t <
2397 detail::is_basic_json<BasicJsonType>::value
2398 && detail::is_getable<basic_json_t, ValueType>::value
2399 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2403 return value(
ptr.convert(), default_value);
2406 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
2407 detail::enable_if_t <
2408 detail::is_basic_json<BasicJsonType>::value
2409 && detail::is_getable<basic_json_t, ReturnType>::value
2410 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
2414 return value(
ptr.convert(), std::forward<ValueType>(default_value));
2451 template <
class IteratorType, detail::enable_if_t <
2452 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
2453 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
2459 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
2462 IteratorType result =
end();
2466 case value_t::boolean:
2467 case value_t::number_float:
2468 case value_t::number_integer:
2469 case value_t::number_unsigned:
2470 case value_t::string:
2471 case value_t::binary:
2475 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
2480 AllocatorType<string_t> alloc;
2481 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_data.m_value.string);
2482 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_data.m_value.string, 1);
2483 m_data.m_value.string =
nullptr;
2487 AllocatorType<binary_t> alloc;
2488 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_data.m_value.binary);
2489 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_data.m_value.binary, 1);
2490 m_data.m_value.binary =
nullptr;
2493 m_data.m_type = value_t::null;
2498 case value_t::object:
2500 result.m_it.object_iterator =
m_data.m_value.object->erase(pos.m_it.object_iterator);
2504 case value_t::array:
2506 result.m_it.array_iterator =
m_data.m_value.array->erase(pos.m_it.array_iterator);
2511 case value_t::discarded:
2513 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
2521 template <
class IteratorType, detail::enable_if_t <
2522 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
2523 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
2524 IteratorType
erase(IteratorType first, IteratorType last)
2529 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
2532 IteratorType result =
end();
2536 case value_t::boolean:
2537 case value_t::number_float:
2538 case value_t::number_integer:
2539 case value_t::number_unsigned:
2540 case value_t::string:
2541 case value_t::binary:
2544 || !last.m_it.primitive_iterator.is_end()))
2546 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
2551 AllocatorType<string_t> alloc;
2552 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_data.m_value.string);
2553 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_data.m_value.string, 1);
2554 m_data.m_value.string =
nullptr;
2558 AllocatorType<binary_t> alloc;
2559 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_data.m_value.binary);
2560 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_data.m_value.binary, 1);
2561 m_data.m_value.binary =
nullptr;
2564 m_data.m_type = value_t::null;
2569 case value_t::object:
2571 result.m_it.object_iterator =
m_data.m_value.object->erase(first.m_it.object_iterator,
2572 last.m_it.object_iterator);
2576 case value_t::array:
2578 result.m_it.array_iterator =
m_data.m_value.array->erase(first.m_it.array_iterator,
2579 last.m_it.array_iterator);
2584 case value_t::discarded:
2586 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
2593 template <
typename KeyType, detail::enable_if_t <
2594 detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
2595 size_type erase_internal(KeyType && key)
2600 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
2603 return m_data.m_value.object->erase(std::forward<KeyType>(key));
2606 template <
typename KeyType, detail::enable_if_t <
2607 !detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
2608 size_type erase_internal(KeyType && key)
2613 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
2616 const auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
2617 if (it != m_data.m_value.object->end())
2619 m_data.m_value.object->erase(it);
2633 return erase_internal(key);
2638 template<
class KeyType, detail::enable_if_t<
2639 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2642 return erase_internal(std::forward<KeyType>(key));
2654 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
2661 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
2678 auto result =
end();
2682 result.m_it.object_iterator =
m_data.m_value.object->find(key);
2692 auto result =
cend();
2696 result.m_it.object_iterator =
m_data.m_value.object->find(key);
2704 template<
class KeyType, detail::enable_if_t<
2705 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2708 auto result =
end();
2712 result.m_it.object_iterator =
m_data.m_value.object->find(std::forward<KeyType>(key));
2720 template<
class KeyType, detail::enable_if_t<
2721 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2724 auto result =
cend();
2728 result.m_it.object_iterator =
m_data.m_value.object->find(std::forward<KeyType>(key));
2744 template<
class KeyType, detail::enable_if_t<
2745 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2749 return is_object() ?
m_data.m_value.object->count(std::forward<KeyType>(key)) : 0;
2754 bool contains(
const typename object_t::key_type& key)
const
2761 template<
class KeyType, detail::enable_if_t<
2762 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
2765 return is_object() &&
m_data.m_value.object->find(std::forward<KeyType>(key)) !=
m_data.m_value.object->end();
2772 return ptr.contains(
this);
2775 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
2779 return ptr.contains(
this);
2908 iteration_proxy<iterator>
items() noexcept
2910 return iteration_proxy<iterator>(*
this);
2915 iteration_proxy<const_iterator>
items() const noexcept
2917 return iteration_proxy<const_iterator>(*
this);
2941 case value_t::array:
2944 return m_data.m_value.array->empty();
2947 case value_t::object:
2950 return m_data.m_value.object->empty();
2953 case value_t::string:
2954 case value_t::boolean:
2955 case value_t::number_integer:
2956 case value_t::number_unsigned:
2957 case value_t::number_float:
2958 case value_t::binary:
2959 case value_t::discarded:
2980 case value_t::array:
2983 return m_data.m_value.array->size();
2986 case value_t::object:
2989 return m_data.m_value.object->size();
2992 case value_t::string:
2993 case value_t::boolean:
2994 case value_t::number_integer:
2995 case value_t::number_unsigned:
2996 case value_t::number_float:
2997 case value_t::binary:
2998 case value_t::discarded:
3013 case value_t::array:
3016 return m_data.m_value.array->max_size();
3019 case value_t::object:
3022 return m_data.m_value.object->max_size();
3026 case value_t::string:
3027 case value_t::boolean:
3028 case value_t::number_integer:
3029 case value_t::number_unsigned:
3030 case value_t::number_float:
3031 case value_t::binary:
3032 case value_t::discarded:
3056 case value_t::number_integer:
3058 m_data.m_value.number_integer = 0;
3062 case value_t::number_unsigned:
3064 m_data.m_value.number_unsigned = 0;
3068 case value_t::number_float:
3070 m_data.m_value.number_float = 0.0;
3074 case value_t::boolean:
3076 m_data.m_value.boolean =
false;
3080 case value_t::string:
3082 m_data.m_value.string->clear();
3086 case value_t::binary:
3088 m_data.m_value.binary->clear();
3092 case value_t::array:
3094 m_data.m_value.array->clear();
3098 case value_t::object:
3100 m_data.m_value.object->clear();
3105 case value_t::discarded:
3118 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ",
type_name()),
this));
3124 m_data.m_type = value_t::array;
3125 m_data.m_value = value_t::array;
3130 const auto old_capacity =
m_data.m_value.array->capacity();
3131 m_data.m_value.array->push_back(std::move(val));
3132 set_parent(
m_data.m_value.array->back(), old_capacity);
3151 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ",
type_name()),
this));
3157 m_data.m_type = value_t::array;
3158 m_data.m_value = value_t::array;
3163 const auto old_capacity =
m_data.m_value.array->capacity();
3164 m_data.m_value.array->push_back(val);
3165 set_parent(
m_data.m_value.array->back(), old_capacity);
3183 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ",
type_name()),
this));
3189 m_data.m_type = value_t::object;
3190 m_data.m_value = value_t::object;
3195 auto res =
m_data.m_value.object->insert(val);
3196 set_parent(res.first->second);
3211 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
3213 basic_json&& key = init.begin()->moved_or_copied();
3214 push_back(
typename object_t::value_type(
3215 std::move(key.
get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
3233 template<
class... Args>
3239 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace_back() with ",
type_name()),
this));
3245 m_data.m_type = value_t::array;
3246 m_data.m_value = value_t::array;
3251 const auto old_capacity =
m_data.m_value.array->capacity();
3252 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
3253 return set_parent(
m_data.m_value.array->back(), old_capacity);
3258 template<
class... Args>
3259 std::pair<iterator, bool>
emplace(Args&& ... args)
3264 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace() with ",
type_name()),
this));
3270 m_data.m_type = value_t::object;
3271 m_data.m_value = value_t::object;
3276 auto res =
m_data.m_value.object->emplace(std::forward<Args>(args)...);
3277 set_parent(res.first->second);
3281 it.m_it.object_iterator = res.first;
3284 return {it, res.second};
3290 template<
typename... Args>
3294 JSON_ASSERT(
m_data.m_value.array !=
nullptr);
3296 auto insert_pos = std::distance(
m_data.m_value.array->begin(), pos.m_it.array_iterator);
3297 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
3298 result.m_it.array_iterator =
m_data.m_value.array->begin() + insert_pos;
3318 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
3325 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
3345 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
3352 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
3362 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
3368 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
3374 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
3379 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
this));
3383 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
3393 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
3399 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
3413 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
3419 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
3425 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects",
this));
3428 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
3446 m_data.m_type = value_t::object;
3447 m_data.m_value.object = create<object_t>();
3453 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ",
type_name()),
this));
3459 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
3465 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", first.m_object->type_name()), first.m_object));
3468 for (
auto it = first; it != last; ++it)
3470 if (merge_objects && it.value().is_object())
3472 auto it2 =
m_data.m_value.object->find(it.key());
3473 if (it2 !=
m_data.m_value.object->end())
3475 it2->second.update(it.value(),
true);
3479 m_data.m_value.object->operator[](it.key()) = it.value();
3481 m_data.m_value.object->operator[](it.key()).m_parent =
this;
3489 std::is_nothrow_move_constructible<value_t>::value&&
3490 std::is_nothrow_move_assignable<value_t>::value&&
3491 std::is_nothrow_move_constructible<json_value>::value&&
3492 std::is_nothrow_move_assignable<json_value>::value
3499 other.set_parents();
3506 std::is_nothrow_move_constructible<value_t>::value&&
3507 std::is_nothrow_move_assignable<value_t>::value&&
3508 std::is_nothrow_move_constructible<json_value>::value&&
3509 std::is_nothrow_move_assignable<json_value>::value
3527 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(array_t&) with ",
type_name()),
this));
3543 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(object_t&) with ",
type_name()),
this));
3559 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(string_t&) with ",
type_name()),
this));
3575 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t&) with ",
type_name()),
this));
3581 void swap(
typename binary_t::container_type& other)
3591 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t::container_type&) with ",
type_name()),
this));
3606#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
3607 const auto lhs_type = lhs.type(); \
3608 const auto rhs_type = rhs.type(); \
3610 if (lhs_type == rhs_type) \
3614 case value_t::array: \
3615 return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \
3617 case value_t::object: \
3618 return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \
3620 case value_t::null: \
3621 return (null_result); \
3623 case value_t::string: \
3624 return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \
3626 case value_t::boolean: \
3627 return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \
3629 case value_t::number_integer: \
3630 return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \
3632 case value_t::number_unsigned: \
3633 return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \
3635 case value_t::number_float: \
3636 return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \
3638 case value_t::binary: \
3639 return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \
3641 case value_t::discarded: \
3643 return (unordered_result); \
3646 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
3648 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \
3650 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
3652 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \
3654 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
3656 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \
3658 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
3660 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \
3662 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
3664 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \
3666 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
3668 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \
3670 else if(compares_unordered(lhs, rhs))\
3672 return (unordered_result);\
3675 return (default_result);
3677 JSON_PRIVATE_UNLESS_TESTED:
3686 || (
rhs.is_number_float() && std::isnan(
rhs.m_data.m_value.number_float) && lhs.
is_number()))
3690#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
3699 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept
3701 return compares_unordered(*
this, rhs, inverse);
3705#if JSON_HAS_THREE_WAY_COMPARISON
3708 bool operator==(const_reference rhs)
const noexcept
3711#pragma GCC diagnostic push
3712#pragma GCC diagnostic ignored "-Wfloat-equal"
3714 const_reference lhs = *
this;
3717#pragma GCC diagnostic pop
3723 template<
typename ScalarType>
3724 requires std::is_scalar_v<ScalarType>
3725 bool operator==(ScalarType rhs)
const noexcept
3732 bool operator!=(const_reference rhs)
const noexcept
3734 if (compares_unordered(rhs,
true))
3743 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
3745 const_reference lhs = *
this;
3749 std::partial_ordering::equivalent,
3750 std::partial_ordering::unordered,
3751 lhs_type <=> rhs_type)
3756 template<
typename ScalarType>
3757 requires std::is_scalar_v<ScalarType>
3758 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
3763#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
3770 bool operator<=(const_reference rhs)
const noexcept
3772 if (compares_unordered(rhs,
true))
3776 return !(rhs < *
this);
3781 template<
typename ScalarType>
3782 requires std::is_scalar_v<ScalarType>
3783 bool operator<=(ScalarType rhs)
const noexcept
3791 bool operator>=(const_reference rhs)
const noexcept
3793 if (compares_unordered(rhs,
true))
3797 return !(*
this < rhs);
3802 template<
typename ScalarType>
3803 requires std::is_scalar_v<ScalarType>
3804 bool operator>=(ScalarType rhs)
const noexcept
3812 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept
3815#pragma GCC diagnostic push
3816#pragma GCC diagnostic ignored "-Wfloat-equal"
3820#pragma GCC diagnostic pop
3826 template<
typename ScalarType,
typename std::enable_if<
3827 std::is_scalar<ScalarType>::value,
int>::type = 0>
3828 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept
3835 template<
typename ScalarType,
typename std::enable_if<
3836 std::is_scalar<ScalarType>::value,
int>::type = 0>
3837 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept
3844 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept
3846 if (compares_unordered(lhs, rhs,
true))
3850 return !(lhs == rhs);
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
3883 template<
typename ScalarType,
typename std::enable_if<
3884 std::is_scalar<ScalarType>::value,
int>::type = 0>
3885 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept
3892 template<
typename ScalarType,
typename std::enable_if<
3893 std::is_scalar<ScalarType>::value,
int>::type = 0>
3894 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept
3901 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept
3903 if (compares_unordered(lhs, rhs,
true))
3907 return !(rhs < lhs);
3912 template<
typename ScalarType,
typename std::enable_if<
3913 std::is_scalar<ScalarType>::value,
int>::type = 0>
3914 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept
3921 template<
typename ScalarType,
typename std::enable_if<
3922 std::is_scalar<ScalarType>::value,
int>::type = 0>
3923 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept
3930 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept
3933 if (compares_unordered(lhs, rhs))
3937 return !(lhs <= rhs);
3942 template<
typename ScalarType,
typename std::enable_if<
3943 std::is_scalar<ScalarType>::value,
int>::type = 0>
3944 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept
3951 template<
typename ScalarType,
typename std::enable_if<
3952 std::is_scalar<ScalarType>::value,
int>::type = 0>
3953 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept
3960 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept
3962 if (compares_unordered(lhs, rhs,
true))
3966 return !(lhs < rhs);
3971 template<
typename ScalarType,
typename std::enable_if<
3972 std::is_scalar<ScalarType>::value,
int>::type = 0>
3973 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept
3980 template<
typename ScalarType,
typename std::enable_if<
3981 std::is_scalar<ScalarType>::value,
int>::type = 0>
3982 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept
3988#undef JSON_IMPLEMENT_OPERATOR
4004 const bool pretty_print = o.width() > 0;
4005 const auto indentation = pretty_print ? o.width() : 0;
4011 serializer s(detail::output_adapter<char>(o), o.fill());
4012 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
4023 friend std::ostream& operator>>(
const basic_json& j, std::ostream& o)
4045 template<
typename InputType>
4048 parser_callback_t cb =
nullptr,
4049 const bool allow_exceptions =
true,
4050 const bool ignore_comments =
false)
4053 parser(detail::input_adapter(std::forward<InputType>(i)), std::move(cb), allow_exceptions, ignore_comments).parse(
true, result);
4059 template<
typename IteratorType>
4063 parser_callback_t cb =
nullptr,
4064 const bool allow_exceptions =
true,
4065 const bool ignore_comments =
false)
4068 parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments).parse(
true, result);
4074 static basic_json parse(detail::span_input_adapter&& i,
4075 parser_callback_t cb =
nullptr,
4076 const bool allow_exceptions =
true,
4077 const bool ignore_comments =
false)
4080 parser(i.get(), std::move(cb), allow_exceptions, ignore_comments).parse(
true, result);
4086 template<
typename InputType>
4087 static bool accept(InputType&& i,
4088 const bool ignore_comments =
false)
4090 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
4095 template<
typename IteratorType>
4096 static bool accept(IteratorType first, IteratorType last,
4097 const bool ignore_comments =
false)
4099 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
4104 static bool accept(detail::span_input_adapter&& i,
4105 const bool ignore_comments =
false)
4107 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
4112 template <
typename InputType,
typename SAX>
4116 const
bool strict = true,
4117 const
bool ignore_comments = false)
4119 auto ia = detail::input_adapter(std::forward<InputType>(i));
4120 return format == input_format_t::json
4121 ?
parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
4122 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia),
format).sax_parse(
format, sax, strict);
4127 template<
class IteratorType,
class SAX>
4129 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
4131 const
bool strict = true,
4132 const
bool ignore_comments = false)
4134 auto ia = detail::input_adapter(std::move(first), std::move(last));
4135 return format == input_format_t::json
4136 ?
parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
4137 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia),
format).sax_parse(
format, sax, strict);
4145 template <
typename SAX>
4150 const
bool strict = true,
4151 const
bool ignore_comments = false)
4154 return format == input_format_t::json
4156 ?
parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
4158 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia),
format).sax_parse(
format, sax, strict);
4177 parser(detail::input_adapter(i)).parse(
false, j);
4196 case value_t::object:
4198 case value_t::array:
4200 case value_t::string:
4202 case value_t::boolean:
4204 case value_t::binary:
4206 case value_t::discarded:
4208 case value_t::number_integer:
4209 case value_t::number_unsigned:
4210 case value_t::number_float:
4216 JSON_PRIVATE_UNLESS_TESTED:
4224 value_t m_type = value_t::null;
4237 m_value.array = create<array_t>(cnt, val);
4259#if JSON_DIAGNOSTIC_POSITIONS
4261 std::size_t start_position = std::string::npos;
4263 std::size_t end_position = std::string::npos;
4265 constexpr std::size_t start_pos() const noexcept
4267 return start_position;
4270 constexpr std::size_t end_pos() const noexcept
4272 return end_position;
4288 std::vector<std::uint8_t> result;
4297 binary_writer<std::uint8_t>(o).write_cbor(j);
4304 binary_writer<char>(o).write_cbor(j);
4311 std::vector<std::uint8_t> result;
4320 binary_writer<std::uint8_t>(o).write_msgpack(j);
4327 binary_writer<char>(o).write_msgpack(j);
4333 const bool use_size =
false,
4334 const bool use_type =
false)
4336 std::vector<std::uint8_t> result;
4337 to_ubjson(j, result, use_size, use_type);
4344 const bool use_size =
false,
const bool use_type =
false)
4346 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
4352 const bool use_size =
false,
const bool use_type =
false)
4354 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
4360 const bool use_size =
false,
4361 const bool use_type =
false,
4364 std::vector<std::uint8_t> result;
4365 to_bjdata(j, result, use_size, use_type, version);
4372 const bool use_size =
false,
const bool use_type =
false,
4375 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true, version);
4381 const bool use_size =
false,
const bool use_type =
false,
4384 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true, version);
4391 std::vector<std::uint8_t> result;
4400 binary_writer<std::uint8_t>(o).write_bson(j);
4407 binary_writer<char>(o).write_bson(j);
4412 template<
typename InputType>
4415 const bool strict =
true,
4416 const bool allow_exceptions =
true,
4420 auto ia = detail::input_adapter(std::forward<InputType>(i));
4421 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4422 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4423 return res ? result :
basic_json(value_t::discarded);
4428 template<
typename IteratorType>
4431 const bool strict =
true,
4432 const bool allow_exceptions =
true,
4436 auto ia = detail::input_adapter(std::move(first), std::move(last));
4437 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4438 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4439 return res ? result :
basic_json(value_t::discarded);
4442 template<
typename T>
4446 const
bool strict = true,
4447 const
bool allow_exceptions = true,
4450 return from_cbor(
ptr,
ptr + len, strict, allow_exceptions, tag_handler);
4456 const
bool strict = true,
4457 const
bool allow_exceptions = true,
4462 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4464 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4465 return res ? result :
basic_json(value_t::discarded);
4470 template<
typename InputType>
4473 const bool strict =
true,
4474 const bool allow_exceptions =
true)
4477 auto ia = detail::input_adapter(std::forward<InputType>(i));
4478 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4479 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4480 return res ? result :
basic_json(value_t::discarded);
4485 template<
typename IteratorType>
4488 const bool strict =
true,
4489 const bool allow_exceptions =
true)
4492 auto ia = detail::input_adapter(std::move(first), std::move(last));
4493 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4494 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4495 return res ? result :
basic_json(value_t::discarded);
4498 template<
typename T>
4502 const
bool strict = true,
4503 const
bool allow_exceptions = true)
4511 const
bool strict = true,
4512 const
bool allow_exceptions = true)
4516 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4518 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4519 return res ? result :
basic_json(value_t::discarded);
4524 template<
typename InputType>
4527 const bool strict =
true,
4528 const bool allow_exceptions =
true)
4531 auto ia = detail::input_adapter(std::forward<InputType>(i));
4532 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4533 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4534 return res ? result :
basic_json(value_t::discarded);
4539 template<
typename IteratorType>
4542 const bool strict =
true,
4543 const bool allow_exceptions =
true)
4546 auto ia = detail::input_adapter(std::move(first), std::move(last));
4547 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4548 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4549 return res ? result :
basic_json(value_t::discarded);
4552 template<
typename T>
4556 const
bool strict = true,
4557 const
bool allow_exceptions = true)
4565 const
bool strict = true,
4566 const
bool allow_exceptions = true)
4570 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4572 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4573 return res ? result :
basic_json(value_t::discarded);
4578 template<
typename InputType>
4581 const bool strict =
true,
4582 const bool allow_exceptions =
true)
4585 auto ia = detail::input_adapter(std::forward<InputType>(i));
4586 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4587 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
4588 return res ? result :
basic_json(value_t::discarded);
4593 template<
typename IteratorType>
4596 const bool strict =
true,
4597 const bool allow_exceptions =
true)
4600 auto ia = detail::input_adapter(std::move(first), std::move(last));
4601 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4602 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
4603 return res ? result :
basic_json(value_t::discarded);
4608 template<
typename InputType>
4611 const bool strict =
true,
4612 const bool allow_exceptions =
true)
4615 auto ia = detail::input_adapter(std::forward<InputType>(i));
4616 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4617 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4618 return res ? result :
basic_json(value_t::discarded);
4623 template<
typename IteratorType>
4626 const bool strict =
true,
4627 const bool allow_exceptions =
true)
4630 auto ia = detail::input_adapter(std::move(first), std::move(last));
4631 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4632 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4633 return res ? result :
basic_json(value_t::discarded);
4636 template<
typename T>
4640 const
bool strict = true,
4641 const
bool allow_exceptions = true)
4649 const
bool strict = true,
4650 const
bool allow_exceptions = true)
4654 detail::json_sax_dom_parser<
basic_json,
decltype(ia)> sdp(result, allow_exceptions);
4656 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4657 return res ? result :
basic_json(value_t::discarded);
4672 return ptr.get_unchecked(
this);
4675 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
4679 return ptr.get_unchecked(
this);
4686 return ptr.get_unchecked(
this);
4689 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
4693 return ptr.get_unchecked(
this);
4700 return ptr.get_checked(
this);
4703 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
4707 return ptr.get_checked(
this);
4714 return ptr.get_checked(
this);
4717 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
4721 return ptr.get_checked(
this);
4729 json_pointer::flatten(
"", *
this, result);
4737 return json_pointer::unflatten(*
this);
4755 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
4757 const auto get_op = [](
const string_t& op)
4761 return patch_operations::add;
4765 return patch_operations::remove;
4767 if (op ==
"replace")
4769 return patch_operations::replace;
4773 return patch_operations::move;
4777 return patch_operations::copy;
4781 return patch_operations::test;
4784 return patch_operations::invalid;
4799 if (top_pointer !=
ptr)
4801 result.
at(top_pointer);
4805 const auto last_path =
ptr.back();
4810 switch (parent.
m_data.m_type)
4813 case value_t::object:
4816 parent[last_path] = val;
4820 case value_t::array:
4822 if (last_path ==
"-")
4829 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
4833 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"), &parent));
4843 case value_t::string:
4844 case value_t::boolean:
4845 case value_t::number_integer:
4846 case value_t::number_unsigned:
4847 case value_t::number_float:
4848 case value_t::binary:
4849 case value_t::discarded:
4859 const auto last_path =
ptr.back();
4867 auto it = parent.
find(last_path);
4874 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", last_path,
"' not found"),
this));
4880 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
4887 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
4891 for (
const auto& val : json_patch)
4894 const auto get_value = [&val](
const string_t& op,
4899 auto it = val.m_data.m_value.object->find(member);
4902 const auto error_msg = (op ==
"op") ?
"operation" : detail::concat(
"operation '", op,
'\'');
4908 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have member '", member,
"'"), &val));
4915 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have string member '", member,
"'"), &val));
4925 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &val));
4929 const auto op = get_value(
"op",
"op",
true).template
get<string_t>();
4930 const auto path = get_value(op,
"path",
true).template
get<string_t>();
4935 case patch_operations::add:
4937 operation_add(
ptr, get_value(
"add",
"value",
false));
4941 case patch_operations::remove:
4943 operation_remove(
ptr);
4947 case patch_operations::replace:
4950 result.
at(
ptr) = get_value(
"replace",
"value",
false);
4954 case patch_operations::move:
4956 const auto from_path = get_value(
"move",
"from",
true).template
get<string_t>();
4966 operation_remove(from_ptr);
4967 operation_add(
ptr, v);
4971 case patch_operations::copy:
4973 const auto from_path = get_value(
"copy",
"from",
true).template
get<string_t>();
4982 operation_add(
ptr, v);
4986 case patch_operations::test:
4988 bool success =
false;
4993 success = (result.
at(
ptr) == get_value(
"test",
"value",
false));
5003 JSON_THROW(other_error::create(501, detail::concat(
"unsuccessful: ", val.dump()), &val));
5009 case patch_operations::invalid:
5014 JSON_THROW(parse_error::create(105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
5049 {
"op",
"replace"}, {
"path", path}, {
"value", target}
5056 case value_t::array:
5060 while (i <
source.size() && i < target.
size())
5063 auto temp_diff =
diff(
source[i], target[i], detail::concat<string_t>(path,
'/', detail::to_string<string_t>(i)));
5064 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
5073 while (i <
source.size())
5080 {
"path", detail::concat<string_t>(path,
'/', detail::to_string<string_t>(i))}
5086 while (i < target.
size())
5091 {
"path", detail::concat<string_t>(path,
"/-")},
5092 {
"value", target[i]}
5100 case value_t::object:
5103 for (
auto it =
source.cbegin(); it !=
source.cend(); ++it)
5106 const auto path_key = detail::concat<string_t>(path,
'/', detail::escape(it.key()));
5108 if (target.
find(it.key()) != target.
end())
5111 auto temp_diff =
diff(it.value(), target[it.key()], path_key);
5112 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
5119 {
"op",
"remove"}, {
"path", path_key}
5125 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
5130 const auto path_key = detail::concat<string_t>(path,
'/', detail::escape(it.key()));
5133 {
"op",
"add"}, {
"path", path_key},
5134 {
"value", it.value()}
5143 case value_t::string:
5144 case value_t::boolean:
5145 case value_t::number_integer:
5146 case value_t::number_unsigned:
5147 case value_t::number_float:
5148 case value_t::binary:
5149 case value_t::discarded:
5155 {
"op",
"replace"}, {
"path", path}, {
"value", target}
5182 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
5184 if (it.value().is_null())
5190 operator[](it.key()).merge_patch(it.value());
5196 *
this = apply_patch;
5205WPI_BASIC_JSON_TPL_DECLARATION
5219#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
5220 inline wpi::util::json
operator ""_json(
const char* s, std::size_t n)
5222 inline wpi::util::json
operator "" _json(
const char* s, std::size_t n)
5225 return wpi::util::json::parse(s, s + n);
5231#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
5242WPI_JSON_NAMESPACE_END
5253WPI_BASIC_JSON_TPL_DECLARATION
5254struct hash<
wpi::util::WPI_BASIC_JSON_TPL>
5256 std::size_t
operator()(
const wpi::util::WPI_BASIC_JSON_TPL& j)
const
5258 return wpi::util::detail::hash(j);
5264struct less< ::wpi::util::detail::value_t>
5271 ::wpi::util::detail::value_t rhs)
const noexcept
5273#if JSON_HAS_THREE_WAY_COMPARISON
5274 return std::is_lt(lhs <=> rhs);
5276 return ::wpi::util::detail::operator<(lhs, rhs);
5282#ifndef JSON_HAS_CPP_20
5286WPI_BASIC_JSON_TPL_DECLARATION
5287inline void swap(wpi::util::WPI_BASIC_JSON_TPL& j1, wpi::util::WPI_BASIC_JSON_TPL& j2)
noexcept(
5288 is_nothrow_move_constructible<wpi::util::WPI_BASIC_JSON_TPL>::value&&
5289 is_nothrow_move_assignable<wpi::util::WPI_BASIC_JSON_TPL>::value)
5298#if JSON_USE_GLOBAL_UDLS
5299 #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
5300 using wpi::util::literals::json_literals::operator
""_json;
5301 using wpi::util::literals::json_literals::operator
""_json_pointer;
5303 using wpi::util::literals::json_literals::operator
"" _json;
5304 using wpi::util::literals::json_literals::operator
"" _json_pointer;
5308#include <wpi/util/detail/macro_unscope.hpp>
or
Definition ThirdPartyNotices.txt:208
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
you may not use this file except in compliance with the License You may obtain a copy of the License at software distributed under the License is distributed on an AS IS WITHOUT WARRANTIES OR CONDITIONS OF ANY either express or implied See the License for the specific language governing permissions and limitations under the License LLVM Exceptions to the Apache License As an if
Definition ThirdPartyNotices.txt:301
constexpr T & get(wpi::util::array< T, N > &arr) noexcept
Definition array.hpp:66
@ right
Definition base.h:688
@ left
Definition base.h:688
a class to store JSON values
Definition json.hpp:100
constexpr bool is_string() const noexcept
Definition json.hpp:1415
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.hpp:2629
detail::cbor_tag_handler_t cbor_tag_handler_t
Definition json.hpp:172
reference operator[](KeyType &&key)
access specified object element
Definition json.hpp:2197
size_type size() const noexcept
returns the number of elements
Definition json.hpp:2970
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.hpp:4430
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 > {}))
Definition json.hpp:1781
const_iterator end() const noexcept
returns an iterator to one past the last element
Definition json.hpp:2827
reference back()
access the last element
Definition json.hpp:2433
basic_json value_type
Definition json.hpp:209
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.hpp:837
detail::parse_error parse_error
Definition json.hpp:191
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:2843
detail::input_format_t input_format_t
Definition json.hpp:178
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
Definition json.hpp:5022
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
Definition json.hpp:4190
const_reference front() const
access the first element
Definition json.hpp:2426
friend class ::wpi::util::detail::iter_impl
Definition json.hpp:113
constexpr bool is_array() const noexcept
Definition json.hpp:1408
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)
Definition json.hpp:3488
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:2377
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:2746
iter_impl< const basic_json > const_iterator
Definition json.hpp:232
::wpi::util::json_pointer< std::string > json_pointer
Definition json.hpp:166
constexpr bool is_number_integer() const noexcept
Definition json.hpp:1380
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
Definition json.hpp:236
data(size_type cnt, const basic_json &val)
Definition json.hpp:4234
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.hpp:4625
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:4670
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
Definition json.hpp:227
std::size_t size_type
Definition json.hpp:219
detail::type_error type_error
Definition json.hpp:193
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.hpp:1352
::wpi::util::detail::serializer< basic_json > serializer
Definition json.hpp:162
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.hpp:2221
detail::error_handler_t error_handler_t
Definition json.hpp:170
const value_type & const_reference
Definition json.hpp:214
detail::invalid_iterator invalid_iterator
Definition json.hpp:192
void swap(binary_t &other)
exchanges the values
Definition json.hpp:3565
ReferenceType get_ref()
Definition json.hpp:1866
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.hpp:3009
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:3434
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.hpp:1877
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.hpp:1429
JSON_PRIVATE_UNLESS_TESTED const_reference rhs
Definition json.hpp:3683
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.hpp:3225
void push_back(basic_json &&val)
add an object to an array
Definition json.hpp:3113
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.hpp:2166
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:2915
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.hpp:1318
const_reference back() const
access the last element
Definition json.hpp:2442
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.hpp:2524
reference operator+=(const basic_json &val)
add an object to an array
Definition json.hpp:3170
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.hpp:3505
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.hpp:4526
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.hpp:979
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.hpp:3337
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.hpp:4610
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.hpp:242
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.hpp:2029
iterator end() noexcept
returns an iterator to one past the last element
Definition json.hpp:2818
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.hpp:1387
void update(const_iterator first, const_iterator last, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:3441
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.hpp:4389
detail::exception exception
Definition json.hpp:190
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:2850
data m_data
Definition json.hpp:4252
void push_back(initializer_list_t init)
add an object to an object
Definition json.hpp:3209
detail::parser_callback_t< basic_json > parser_callback_t
Definition json.hpp:804
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.hpp:1020
ValueType & get_to(ValueType &v) const
Definition json.hpp:1843
static void to_msgpack(const basic_json &j, detail::output_adapter< char > o)
create a MessagePack serialization of a given JSON value
Definition json.hpp:4325
iterator begin() noexcept
returns an iterator to the first element
Definition json.hpp:2793
detail::parse_event_t parse_event_t
Definition json.hpp:800
JSON_PRIVATE_UNLESS_TESTED const_reference bool inverse
Definition json.hpp:3683
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.hpp:2276
const_iterator cend() const noexcept
Definition json.hpp:2834
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.hpp:4580
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:4712
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.hpp:990
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.hpp:825
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.hpp:4414
basic_json flatten() const
return flattened JSON value
Definition json.hpp:4726
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.hpp:4541
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.hpp:2640
std::vector< basic_json, std::allocator< basic_json > > array_t
Definition json.hpp:343
wpi::util::ordered_map< std::string, basic_json, default_object_comparator_t, std::allocator< std::pair< const std::string, basic_json > > > object_t
Definition json.hpp:335
const binary_t & get_binary() const
get a binary value
Definition json.hpp:1941
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.hpp:3357
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
Definition json.hpp:4751
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:2329
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:4684
value_type & reference
Definition json.hpp:212
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
Definition json.hpp:176
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.hpp:2763
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.hpp:4295
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
create a BSON serialization of a given JSON value
Definition json.hpp:4405
iterator find(const typename object_t::key_type &key)
Definition json.hpp:2676
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.hpp:968
static std::vector< std::uint8_t > to_bjdata(const basic_json &j, const bool use_size=false, const bool use_type=false, const bjdata_version_t version=bjdata_version_t::draft2)
create a BJData serialization of a given JSON value
Definition json.hpp:4359
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.hpp:2067
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.hpp:250
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.hpp:1027
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.hpp:2690
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:4286
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.hpp:2454
friend class ::wpi::util::detail::binary_writer
Definition json.hpp:115
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.hpp:3310
double number_float_t
Definition json.hpp:363
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:2251
std::allocator< basic_json > allocator_type
Definition json.hpp:222
typename std::allocator_traits< allocator_type >::pointer pointer
Definition json.hpp:225
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.hpp:1298
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.hpp:5174
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.hpp:1830
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, const bjdata_version_t version=bjdata_version_t::draft2)
create a BJData serialization of a given JSON value
Definition json.hpp:4371
reference operator[](T *key)
Definition json.hpp:2182
reference at(size_type idx)
access specified array element with bounds checking
Definition json.hpp:1963
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.hpp:2706
constexpr bool is_number_float() const noexcept
Definition json.hpp:1394
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.hpp:2857
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.hpp:4332
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:4698
bool boolean_t
Definition json.hpp:351
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json diff(const basic_json &source, const basic_json &target, const string_t &path="")
creates a diff as a JSON patch
Definition json.hpp:5032
detail::value_t value_t
Definition json.hpp:164
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.hpp:330
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:3201
const_iterator cbegin() const noexcept
Definition json.hpp:2809
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.hpp:2144
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.hpp:1600
~basic_json() noexcept
destructor
Definition json.hpp:1280
detail::out_of_range out_of_range
Definition json.hpp:194
const_reverse_iterator crend() const noexcept
Definition json.hpp:2878
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.hpp:909
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.hpp:3581
binary_t & get_binary()
get a binary value
Definition json.hpp:1929
const_iterator begin() const noexcept
returns an iterator to the first element
Definition json.hpp:2802
constexpr bool is_number() const noexcept
Definition json.hpp:1373
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.hpp:3408
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.hpp:4472
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:1817
const_reference operator[](T *key) const
Definition json.hpp:2188
friend class ::wpi::util::detail::binary_reader
Definition json.hpp:117
data(const value_t v)
Definition json.hpp:4229
reference operator[](size_type idx)
access specified array element
Definition json.hpp:2085
basic_json(const JsonRef &ref)
Definition json.hpp:1148
adl_serializer< T, SFINAE > json_serializer
Definition json.hpp:168
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.hpp:1251
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
Definition json.hpp:2890
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.hpp:4351
Array get_to(T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v)))
Definition json.hpp:1854
std::int64_t number_integer_t
Definition json.hpp:355
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:1589
friend class ::wpi::util::detail::parser
Definition json.hpp:110
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.hpp:2047
wpi::util::byte_container_with_subtype< std::vector< std::uint8_t > > binary_t
Definition json.hpp:367
constexpr bool is_binary() const noexcept
Definition json.hpp:1422
void swap(object_t &other)
exchanges the values
Definition json.hpp:3533
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.hpp:4735
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.hpp:3388
static void to_bjdata(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false, const bjdata_version_t version=bjdata_version_t::draft2)
create a BJData serialization of a given JSON value
Definition json.hpp:4380
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.hpp:1001
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:2908
bool empty() const noexcept
checks whether the container is empty.
Definition json.hpp:2931
void swap(array_t &other)
exchanges the values
Definition json.hpp:3517
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.hpp:2647
reference operator+=(basic_json &&val)
add an object to an array
Definition json.hpp:3138
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.hpp:2770
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.hpp:1338
reference emplace_back(Args &&... args)
add an object to an array
Definition json.hpp:3234
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:2352
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.hpp:1012
detail::bjdata_version_t bjdata_version_t
Definition json.hpp:174
std::string string_t
Definition json.hpp:347
void push_back(const basic_json &val)
add an object to an array
Definition json.hpp:3146
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:2302
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.hpp:2009
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.hpp:4595
json_value m_value
Definition json.hpp:4227
const_reverse_iterator crbegin() const noexcept
Definition json.hpp:2871
json_sax< basic_json > json_sax_t
Definition json.hpp:180
constexpr bool is_boolean() const noexcept
Definition json.hpp:1366
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.hpp:2736
reference front()
access the first element
Definition json.hpp:2419
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.hpp:1345
constexpr bool is_null() const noexcept
Definition json.hpp:1359
void clear() noexcept
clears the contents
Definition json.hpp:3052
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.hpp:4343
detail::other_error other_error
Definition json.hpp:195
JSON_PRIVATE_UNLESS_TESTED const_reference bool static SAX bool sax_parse(InputType &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)
Definition json.hpp:4114
basic_json(basic_json &&other) noexcept
move constructor
Definition json.hpp:1225
iter_impl< basic_json > iterator
Definition json.hpp:230
basic_json(const value_t v)
create an empty value with a given type
Definition json.hpp:817
const_reference operator[](size_type idx) const
access specified array element
Definition json.hpp:2131
std::ptrdiff_t difference_type
Definition json.hpp:217
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.hpp:3330
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
Definition json.hpp:2864
std::uint64_t number_unsigned_t
Definition json.hpp:359
friend std::istream & operator>>(std::istream &i, basic_json &j)
Definition json.hpp:4175
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.hpp:4309
void swap(string_t &other)
exchanges the values
Definition json.hpp:3549
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.hpp:851
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
Definition json.hpp:234
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.hpp:1986
detail::actual_object_comparator_t< basic_json > object_comparator_t
Definition json.hpp:371
basic_json(const basic_json &other)
copy constructor
Definition json.hpp:1152
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:3178
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.hpp:3259
static void to_cbor(const basic_json &j, detail::output_adapter< char > o)
create a CBOR serialization of a given JSON value
Definition json.hpp:4302
constexpr bool is_object() const noexcept
Definition json.hpp:1401
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.hpp:4318
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.hpp:4487
iterator insert_iterator(const_iterator pos, Args &&... args)
Helper for insertion of an iterator.
Definition json.hpp:3291
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.hpp:1039
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.hpp:2754
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.hpp:4398
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.hpp:2722
#define JSON_HEDLEY_WARN_UNUSED_RESULT
Definition hedley.hpp:1130
#define JSON_HEDLEY_LIKELY(expr)
Definition hedley.hpp:1395
#define JSON_HEDLEY_NON_NULL(...)
Definition hedley.hpp:1288
#define JSON_HEDLEY_RETURNS_NON_NULL
Definition hedley.hpp:1729
#define JSON_HEDLEY_UNLIKELY(expr)
Definition hedley.hpp:1396
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
Definition hedley.hpp:1078
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.hpp:5206
#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result)
Definition json.hpp:3606
basic_json<> json
default specialization
Definition json_fwd.hpp:62
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
Definition StringMap.hpp:773
void swap(wpi::util::StringMap< T > &lhs, wpi::util::StringMap< T > &rhs)
Definition StringMap.hpp:775
@ binary
Definition argparse.hpp:204
raw_ostream & operator<<(raw_ostream &OS, sys::TimePoint<> TP)
constexpr bool operator<(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:184
constexpr bool operator!=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:180
constexpr bool operator>(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:192
constexpr bool operator<=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:188
array(T, Ts...) -> array< T, 1+sizeof...(Ts)>
constexpr bool operator>=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:196
constexpr bool operator==(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:176
Definition CvSource.hpp:15
@ string
Definition ranges.h:31
std::size_t operator()(const wpi::util::WPI_BASIC_JSON_TPL &j) const
Definition json.hpp:5256
bool operator()(::wpi::util::detail::value_t lhs, ::wpi::util::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.hpp:5270