30 #ifndef INCLUDE_NLOHMANN_JSON_HPP_
31 #define INCLUDE_NLOHMANN_JSON_HPP_
33 #define NLOHMANN_JSON_VERSION_MAJOR 3
34 #define NLOHMANN_JSON_VERSION_MINOR 10
35 #define NLOHMANN_JSON_VERSION_PATCH 3
40 #include <initializer_list>
51 #include <nlohmann/adl_serializer.hpp>
52 #include <nlohmann/byte_container_with_subtype.hpp>
53 #include <nlohmann/detail/conversions/from_json.hpp>
54 #include <nlohmann/detail/conversions/to_json.hpp>
55 #include <nlohmann/detail/exceptions.hpp>
56 #include <nlohmann/detail/hash.hpp>
57 #include <nlohmann/detail/input/binary_reader.hpp>
58 #include <nlohmann/detail/input/input_adapters.hpp>
59 #include <nlohmann/detail/input/lexer.hpp>
60 #include <nlohmann/detail/input/parser.hpp>
61 #include <nlohmann/detail/iterators/internal_iterator.hpp>
62 #include <nlohmann/detail/iterators/iter_impl.hpp>
63 #include <nlohmann/detail/iterators/iteration_proxy.hpp>
64 #include <nlohmann/detail/iterators/json_reverse_iterator.hpp>
65 #include <nlohmann/detail/iterators/primitive_iterator.hpp>
66 #include <nlohmann/detail/json_pointer.hpp>
67 #include <nlohmann/detail/json_ref.hpp>
68 #include <nlohmann/detail/macro_scope.hpp>
69 #include <nlohmann/detail/string_escape.hpp>
70 #include <nlohmann/detail/meta/cpp_future.hpp>
71 #include <nlohmann/detail/meta/type_traits.hpp>
72 #include <nlohmann/detail/output/binary_writer.hpp>
73 #include <nlohmann/detail/output/output_adapters.hpp>
74 #include <nlohmann/detail/output/serializer.hpp>
75 #include <nlohmann/detail/value_t.hpp>
76 #include <nlohmann/json_fwd.hpp>
77 #include <nlohmann/ordered_map.hpp>
79 #if defined(JSON_HAS_CPP_17)
80 #include <string_view>
175 NLOHMANN_BASIC_JSON_TPL_DECLARATION
180 friend ::nlohmann::json_pointer<basic_json>;
182 template<
typename BasicJsonType,
typename InputType>
183 friend class ::nlohmann::detail::parser;
184 friend ::nlohmann::detail::serializer<basic_json>;
185 template<
typename BasicJsonType>
186 friend class ::nlohmann::detail::iter_impl;
187 template<
typename BasicJsonType,
typename CharType>
188 friend class ::nlohmann::detail::binary_writer;
189 template<
typename BasicJsonType,
typename InputType,
typename SAX>
190 friend class ::nlohmann::detail::binary_reader;
191 template<
typename BasicJsonType>
192 friend class ::nlohmann::detail::json_sax_dom_parser;
193 template<
typename BasicJsonType>
194 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
195 friend class ::nlohmann::detail::exception;
198 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
200 JSON_PRIVATE_UNLESS_TESTED:
204 template<
typename InputAdapterType>
205 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
206 InputAdapterType adapter,
207 detail::parser_callback_t<basic_json>cb =
nullptr,
208 const bool allow_exceptions =
true,
209 const bool ignore_comments =
false
212 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
213 std::move(cb), allow_exceptions, ignore_comments);
218 template<
typename BasicJsonType>
220 template<
typename BasicJsonType>
222 template<
typename Iterator>
226 template<
typename CharType>
229 template<
typename InputType>
233 JSON_PRIVATE_UNLESS_TESTED:
240 template<
typename T,
typename SFINAE>
241 using json_serializer = JSONSerializer<T, SFINAE>;
303 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
305 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
353 JSON_HEDLEY_WARN_UNUSED_RESULT
358 result[
"copyright"] =
"(C) 2013-2021 Niels Lohmann";
359 result[
"name"] =
"JSON for Modern C++";
360 result[
"url"] =
"https://github.com/nlohmann/json";
361 result[
"version"][
"string"] =
362 std::to_string(NLOHMANN_JSON_VERSION_MAJOR) +
"." +
363 std::to_string(NLOHMANN_JSON_VERSION_MINOR) +
"." +
364 std::to_string(NLOHMANN_JSON_VERSION_PATCH);
365 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
366 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
367 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
370 result[
"platform"] =
"win32";
371 #elif defined __linux__
372 result[
"platform"] =
"linux";
373 #elif defined __APPLE__
374 result[
"platform"] =
"apple";
375 #elif defined __unix__
376 result[
"platform"] =
"unix";
378 result[
"platform"] =
"unknown";
381 #if defined(__ICC) || defined(__INTEL_COMPILER)
382 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
383 #elif defined(__clang__)
384 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
385 #elif defined(__GNUC__) || defined(__GNUG__)
386 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." + std::to_string(__GNUC_PATCHLEVEL__)}};
387 #elif defined(__HP_cc) || defined(__HP_aCC)
388 result[
"compiler"] =
"hp"
389 #elif defined(__IBMCPP__)
390 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
391 #elif defined(_MSC_VER)
392 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
394 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
395 #elif defined(__SUNPRO_CC)
396 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
398 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
402 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
404 result[
"compiler"][
"c++"] =
"unknown";
419 #if defined(JSON_HAS_CPP_14)
422 using object_comparator_t = std::less<>;
424 using object_comparator_t = std::less<StringType>;
513 AllocatorType<std::pair<
const StringType,
560 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
927 template<
typename T,
typename... Args>
928 JSON_HEDLEY_RETURNS_NON_NULL
929 static T* create(Args&& ... args)
931 AllocatorType<T> alloc;
932 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
934 auto deleter = [&](T * obj)
936 AllocatorTraits::deallocate(alloc, obj, 1);
938 std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
939 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
940 JSON_ASSERT(obj !=
nullptr);
941 return obj.release();
948 JSON_PRIVATE_UNLESS_TESTED:
994 json_value() =
default;
996 json_value(
boolean_t v) noexcept : boolean(v) {}
1004 json_value(value_t t)
1010 object = create<object_t>();
1016 array = create<array_t>();
1022 string = create<string_t>(
"");
1028 binary = create<binary_t>();
1068 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.10.3",
basic_json()));
1078 string = create<string_t>(
value);
1084 string = create<string_t>(std::move(
value));
1090 object = create<object_t>(
value);
1096 object = create<object_t>(std::move(
value));
1135 void destroy(value_t t)
1140 std::vector<basic_json> stack;
1145 stack.reserve(
array->size());
1146 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
1151 for (
auto&& it : *
object)
1153 stack.push_back(std::move(it.second));
1157 while (!stack.empty())
1160 basic_json current_item(std::move(stack.back()));
1165 if (current_item.is_array())
1167 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
1169 current_item.m_value.array->clear();
1171 else if (current_item.is_object())
1173 for (
auto&& it : *current_item.m_value.object)
1175 stack.push_back(std::move(it.second));
1178 current_item.m_value.object->clear();
1190 AllocatorType<object_t> alloc;
1191 std::allocator_traits<decltype(alloc)>::destroy(alloc,
object);
1192 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
object, 1);
1198 AllocatorType<array_t> alloc;
1199 std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
1200 std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
1206 AllocatorType<string_t> alloc;
1207 std::allocator_traits<decltype(alloc)>::destroy(alloc,
string);
1208 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
string, 1);
1214 AllocatorType<binary_t> alloc;
1215 std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
1216 std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
1253 void assert_invariant(
bool check_parents =
true) const noexcept
1260 #if JSON_DIAGNOSTICS
1266 return j.m_parent ==
this;
1271 static_cast<void>(check_parents);
1276 #if JSON_DIAGNOSTICS
1281 for (
auto& element : *
m_value.array)
1283 element.m_parent =
this;
1290 for (
auto& element : *
m_value.object)
1292 element.second.m_parent =
this;
1313 #if JSON_DIAGNOSTICS
1316 (it + i)->m_parent =
this;
1319 static_cast<void>(
count);
1326 #if JSON_DIAGNOSTICS
1327 if (old_capacity != std::size_t(-1))
1331 if (JSON_HEDLEY_UNLIKELY(
m_value.array->capacity() != old_capacity))
1341 #ifdef JSON_HEDLEY_MSVC_VERSION
1342 #pragma warning(push )
1343 #pragma warning(disable : 4127)
1345 if (detail::is_ordered_map<object_t>::value)
1350 #ifdef JSON_HEDLEY_MSVC_VERSION
1351 #pragma warning( pop )
1356 static_cast<void>(j);
1357 static_cast<void>(old_capacity);
1566 template <
typename CompatibleType,
1567 typename U = detail::uncvref_t<CompatibleType>,
1568 detail::enable_if_t <
1571 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
1572 std::forward<CompatibleType>(val))))
1574 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
1605 template <
typename BasicJsonType,
1606 detail::enable_if_t <
1610 using other_boolean_t =
typename BasicJsonType::boolean_t;
1611 using other_number_float_t =
typename BasicJsonType::number_float_t;
1612 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
1613 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
1614 using other_string_t =
typename BasicJsonType::string_t;
1615 using other_object_t =
typename BasicJsonType::object_t;
1616 using other_array_t =
typename BasicJsonType::array_t;
1617 using other_binary_t =
typename BasicJsonType::binary_t;
1622 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
1625 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
1628 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
1631 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
1634 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
1637 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
1640 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
1643 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
1733 bool type_deduction =
true,
1738 bool is_an_object = std::all_of(init.begin(), init.end(),
1741 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
1745 if (!type_deduction)
1750 is_an_object =
false;
1754 if (JSON_HEDLEY_UNLIKELY(manual_type ==
value_t::object && !is_an_object))
1756 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
basic_json()));
1766 for (
auto& element_ref : init)
1768 auto element = element_ref.moved_or_copied();
1770 std::move(*((*element.m_value.array)[0].m_value.string)),
1771 std::move((*element.m_value.array)[1]));
1778 m_value.array = create<array_t>(init.begin(), init.end());
1812 JSON_HEDLEY_WARN_UNUSED_RESULT
1849 JSON_HEDLEY_WARN_UNUSED_RESULT
1854 res.m_value =
binary_t(init, subtype);
1859 JSON_HEDLEY_WARN_UNUSED_RESULT
1864 res.m_value = std::move(init);
1869 JSON_HEDLEY_WARN_UNUSED_RESULT
1874 res.m_value =
binary_t(std::move(init), subtype);
1915 JSON_HEDLEY_WARN_UNUSED_RESULT
1959 JSON_HEDLEY_WARN_UNUSED_RESULT
1990 m_value.array = create<array_t>(cnt, val);
2050 template <
class InputIT,
typename std::enable_if <
2051 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
2052 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
2055 JSON_ASSERT(first.m_object !=
nullptr);
2056 JSON_ASSERT(last.m_object !=
nullptr);
2059 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
2061 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
basic_json()));
2065 m_type = first.m_object->m_type;
2076 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
2077 || !last.m_it.primitive_iterator.is_end()))
2079 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *first.m_object));
2097 m_value.number_integer = first.m_object->m_value.number_integer;
2103 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
2109 m_value.number_float = first.m_object->m_value.number_float;
2115 m_value.boolean = first.m_object->m_value.boolean;
2121 m_value = *first.m_object->m_value.string;
2127 m_value.object = create<object_t>(first.m_it.object_iterator,
2128 last.m_it.object_iterator);
2134 m_value.array = create<array_t>(first.m_it.array_iterator,
2135 last.m_it.array_iterator);
2141 m_value = *first.m_object->m_value.binary;
2148 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
2160 template<
typename JsonRef,
2161 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
2162 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
2191 : m_type(other.m_type)
2194 other.assert_invariant();
2283 : m_type(std::move(other.m_type)),
2284 m_value(std::move(other.m_value))
2287 other.assert_invariant(
false);
2321 std::is_nothrow_move_constructible<value_t>::value&&
2322 std::is_nothrow_move_assignable<value_t>::value&&
2323 std::is_nothrow_move_constructible<json_value>::value&&
2324 std::is_nothrow_move_assignable<json_value>::value
2328 other.assert_invariant();
2331 swap(m_type, other.m_type);
2356 assert_invariant(
false);
2419 const char indent_char =
' ',
2420 const bool ensure_ascii =
false,
2428 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
2432 s.dump(*
this,
false, ensure_ascii, 0);
2849 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(
type_name()), *
this));
2871 constexpr
const array_t* get_impl_ptr(
const array_t* )
const noexcept
2959 template<
typename ReferenceType,
typename ThisType>
2960 static ReferenceType get_ref_impl(ThisType& obj)
2963 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
2965 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
2970 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
3004 template<
typename PointerType,
typename std::enable_if<
3005 std::is_pointer<PointerType>::value,
int>
::type = 0>
3006 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
3009 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
3016 template <
typename PointerType,
typename std::enable_if <
3017 std::is_pointer<PointerType>::value&&
3018 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int >
::type = 0 >
3019 constexpr
auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
3022 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
3064 template <
typename ValueType,
3065 detail::enable_if_t <
3070 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
3073 JSONSerializer<ValueType>::from_json(*
this, ret);
3107 template <
typename ValueType,
3108 detail::enable_if_t <
3109 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
3111 ValueType get_impl(detail::priority_tag<1> )
const noexcept(noexcept(
3112 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
3114 return JSONSerializer<ValueType>::from_json(*
this);
3132 template <
typename BasicJsonType,
3133 detail::enable_if_t <
3134 detail::is_basic_json<BasicJsonType>::value,
3136 BasicJsonType get_impl(detail::priority_tag<2> )
const
3155 template<
typename BasicJsonType,
3156 detail::enable_if_t<
3157 std::is_same<BasicJsonType, basic_json_t>::value,
3159 basic_json get_impl(detail::priority_tag<3> )
const
3168 template<
typename PointerType,
3169 detail::enable_if_t<
3170 std::is_pointer<PointerType>::value,
3172 constexpr
auto get_impl(detail::priority_tag<4> )
const noexcept
3173 -> decltype(std::declval<const basic_json_t&>().
template get_ptr<PointerType>())
3176 return get_ptr<PointerType>();
3203 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
3204 #if defined(JSON_HAS_CPP_14)
3208 noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})))
3214 static_assert(!std::is_reference<ValueTypeCV>::value,
3215 "get() cannot be used with reference types, you might want to use get_ref()");
3216 return get_impl<ValueType>(detail::priority_tag<4> {});
3246 template<
typename PointerType,
typename std::enable_if<
3247 std::is_pointer<PointerType>::value,
int>
::type = 0>
3248 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template
get_ptr<PointerType>())
3251 return get_ptr<PointerType>();
3287 template <
typename ValueType,
3288 detail::enable_if_t <
3292 ValueType &
get_to(ValueType& v)
const noexcept(noexcept(
3293 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
3295 JSONSerializer<ValueType>::from_json(*
this, v);
3301 template<
typename ValueType,
3302 detail::enable_if_t <
3305 ValueType &
get_to(ValueType& v)
const
3312 typename T, std::size_t N,
3313 typename Array = T (&)[N],
3314 detail::enable_if_t <
3315 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
3316 Array
get_to(T (&v)[N])
const
3317 noexcept(noexcept(JSONSerializer<Array>::from_json(
3318 std::declval<const basic_json_t&>(), v)))
3320 JSONSerializer<Array>::from_json(*
this, v);
3350 template<
typename ReferenceType,
typename std::enable_if<
3351 std::is_reference<ReferenceType>::value,
int>
::type = 0>
3355 return get_ref_impl<ReferenceType>(*
this);
3362 template <
typename ReferenceType,
typename std::enable_if <
3363 std::is_reference<ReferenceType>::value&&
3364 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int >
::type = 0 >
3368 return get_ref_impl<ReferenceType>(*
this);
3400 template <
typename ValueType,
typename std::enable_if <
3408 #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
3413 JSON_EXPLICIT
operator ValueType()
const
3416 return get<ValueType>();
3432 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
3435 return *get_ptr<binary_t*>();
3443 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
3446 return *get_ptr<const binary_t*>();
3489 if (JSON_HEDLEY_LIKELY(
is_array()))
3493 return set_parent(
m_value.array->at(idx));
3495 JSON_CATCH (std::out_of_range&)
3498 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
3503 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
3536 if (JSON_HEDLEY_LIKELY(
is_array()))
3540 return m_value.array->at(idx);
3542 JSON_CATCH (std::out_of_range&)
3545 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
3550 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
3591 return set_parent(
m_value.object->at(key));
3593 JSON_CATCH (std::out_of_range&)
3596 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
3601 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
3642 return m_value.object->at(key);
3644 JSON_CATCH (std::out_of_range&)
3647 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
3652 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
3687 m_value.array = create<array_t>();
3692 if (JSON_HEDLEY_LIKELY(
is_array()))
3695 if (idx >=
m_value.array->size())
3697 #if JSON_DIAGNOSTICS
3699 const auto old_size =
m_value.array->size();
3700 const auto old_capacity =
m_value.array->capacity();
3702 m_value.array->resize(idx + 1);
3704 #if JSON_DIAGNOSTICS
3705 if (JSON_HEDLEY_UNLIKELY(
m_value.array->capacity() != old_capacity))
3719 return m_value.array->operator[](idx);
3722 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
3747 if (JSON_HEDLEY_LIKELY(
is_array()))
3749 return m_value.array->operator[](idx);
3752 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
3788 m_value.object = create<object_t>();
3795 return set_parent(
m_value.object->operator[](key));
3798 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
3837 return m_value.object->find(key)->second;
3840 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
3870 template<
typename T>
3871 JSON_HEDLEY_NON_NULL(2)
3885 return set_parent(
m_value.object->operator[](key));
3888 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
3921 template<
typename T>
3922 JSON_HEDLEY_NON_NULL(2)
3929 return m_value.object->find(key)->second;
3932 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
3986 template <
class ValueType,
typename std::enable_if <
3988 && !std::is_same<value_t, ValueType>::value,
int >
::type = 0 >
3989 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
3995 const auto it =
find(key);
3998 return it->template get<ValueType>();
4001 return default_value;
4004 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
4011 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const
4059 template<
class ValueType,
typename std::enable_if<
4069 return ptr.get_checked(
this).template get<ValueType>();
4073 return default_value;
4077 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
4084 JSON_HEDLEY_NON_NULL(3)
4222 template <
class IteratorType,
typename std::enable_if <
4223 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
4224 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
4229 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
4231 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
4234 IteratorType result =
end();
4245 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
4247 JSON_THROW(invalid_iterator::create(205,
"iterator out of range", *
this));
4252 AllocatorType<string_t> alloc;
4253 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
4254 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
4259 AllocatorType<binary_t> alloc;
4260 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
4261 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
4272 result.m_it.object_iterator =
m_value.object->erase(pos.m_it.object_iterator);
4278 result.m_it.array_iterator =
m_value.array->erase(pos.m_it.array_iterator);
4285 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
4337 template <
class IteratorType,
typename std::enable_if <
4338 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
4339 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
4341 IteratorType
erase(IteratorType first, IteratorType last)
4344 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
4346 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value", *
this));
4349 IteratorType result =
end();
4360 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
4361 || !last.m_it.primitive_iterator.is_end()))
4363 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *
this));
4368 AllocatorType<string_t> alloc;
4369 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
4370 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
4375 AllocatorType<binary_t> alloc;
4376 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
4377 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
4388 result.m_it.object_iterator =
m_value.object->erase(first.m_it.object_iterator,
4389 last.m_it.object_iterator);
4395 result.m_it.array_iterator =
m_value.array->erase(first.m_it.array_iterator,
4396 last.m_it.array_iterator);
4403 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
4443 return m_value.object->erase(key);
4446 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
4476 if (JSON_HEDLEY_LIKELY(
is_array()))
4478 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
4480 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
4487 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
4525 template<
typename KeyT>
4528 auto result =
end();
4532 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
4542 template<
typename KeyT>
4545 auto result =
cend();
4549 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
4576 template<
typename KeyT>
4608 template <
typename KeyT,
typename std::enable_if <
4643 return ptr.contains(
this);
4987 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
4996 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
5148 return m_value.array->empty();
5154 return m_value.object->empty();
5234 return m_value.object->size();
5300 return m_value.array->max_size();
5306 return m_value.object->max_size();
5456 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
5468 const auto old_capacity =
m_value.array->capacity();
5469 m_value.array->push_back(std::move(val));
5470 set_parent(
m_value.array->back(), old_capacity);
5493 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
5505 const auto old_capacity =
m_value.array->capacity();
5506 m_value.array->push_back(val);
5507 set_parent(
m_value.array->back(), old_capacity);
5545 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
5557 auto res =
m_value.object->insert(val);
5558 set_parent(res.first->second);
5598 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
5600 basic_json&& key = init.begin()->moved_or_copied();
5601 push_back(
typename object_t::value_type(
5602 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
5643 template<
class... Args>
5649 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(
type_name()), *
this));
5661 const auto old_capacity =
m_value.array->capacity();
5662 m_value.array->emplace_back(std::forward<Args>(args)...);
5663 return set_parent(
m_value.array->back(), old_capacity);
5693 template<
class... Args>
5694 std::pair<iterator, bool>
emplace(Args&& ... args)
5699 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(
type_name()), *
this));
5711 auto res =
m_value.object->emplace(std::forward<Args>(args)...);
5712 set_parent(res.first->second);
5716 it.m_it.object_iterator = res.first;
5719 return {it, res.second};
5725 template<
typename... Args>
5729 JSON_ASSERT(
m_value.array !=
nullptr);
5768 if (JSON_HEDLEY_LIKELY(
is_array()))
5771 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
5773 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
5780 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
5819 if (JSON_HEDLEY_LIKELY(
is_array()))
5822 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
5824 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
5831 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
5867 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
5869 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
5873 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
5875 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
5879 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
5881 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
5884 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
5886 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container", *
this));
5920 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
5922 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
5926 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
5928 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
5963 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
5967 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
5969 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
5973 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
5975 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
6006 m_value.object = create<object_t>();
6012 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
6014 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
6016 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.type_name()), *
this));
6019 for (
auto it = j.cbegin(); it != j.cend(); ++it)
6021 m_value.object->operator[](it.key()) = it.value();
6022 #if JSON_DIAGNOSTICS
6023 m_value.object->operator[](it.key()).m_parent =
this;
6060 m_value.object = create<object_t>();
6066 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
6070 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
6072 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
6076 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
6077 || !last.m_object->is_object()))
6079 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
6082 for (
auto it = first; it != last; ++it)
6084 m_value.object->operator[](it.key()) = it.value();
6085 #if JSON_DIAGNOSTICS
6086 m_value.object->operator[](it.key()).m_parent =
this;
6109 std::is_nothrow_move_constructible<value_t>::value&&
6110 std::is_nothrow_move_assignable<value_t>::value&&
6111 std::is_nothrow_move_constructible<json_value>::value&&
6112 std::is_nothrow_move_assignable<json_value>::value
6115 std::swap(m_type, other.m_type);
6116 std::swap(
m_value, other.m_value);
6119 other.set_parents();
6142 std::is_nothrow_move_constructible<value_t>::value&&
6143 std::is_nothrow_move_assignable<value_t>::value&&
6144 std::is_nothrow_move_constructible<json_value>::value&&
6145 std::is_nothrow_move_assignable<json_value>::value
6174 if (JSON_HEDLEY_LIKELY(
is_array()))
6176 std::swap(*(
m_value.array), other);
6180 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
6209 std::swap(*(
m_value.object), other);
6213 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
6242 std::swap(*(
m_value.string), other);
6246 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
6275 std::swap(*(
m_value.binary), other);
6279 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
6289 std::swap(*(
m_value.binary), other);
6293 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
6365 #pragma GCC diagnostic push
6366 #pragma GCC diagnostic ignored "-Wfloat-equal"
6368 const auto lhs_type = lhs.type();
6369 const auto rhs_type = rhs.type();
6371 if (lhs_type == rhs_type)
6376 return *lhs.m_value.array == *rhs.m_value.array;
6379 return *lhs.m_value.object == *rhs.m_value.object;
6385 return *lhs.m_value.string == *rhs.m_value.string;
6388 return lhs.m_value.boolean == rhs.m_value.boolean;
6391 return lhs.m_value.number_integer == rhs.m_value.number_integer;
6394 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
6397 return lhs.m_value.number_float == rhs.m_value.number_float;
6400 return *lhs.m_value.binary == *rhs.m_value.binary;
6409 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
6413 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
6417 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
6421 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
6425 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
6429 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
6434 #pragma GCC diagnostic pop
6442 template<
typename ScalarType,
typename std::enable_if<
6443 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6453 template<
typename ScalarType,
typename std::enable_if<
6454 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6480 return !(lhs == rhs);
6487 template<
typename ScalarType,
typename std::enable_if<
6488 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6498 template<
typename ScalarType,
typename std::enable_if<
6499 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6533 const auto lhs_type = lhs.type();
6534 const auto rhs_type = rhs.type();
6536 if (lhs_type == rhs_type)
6543 return (*lhs.m_value.array) < (*rhs.m_value.array);
6546 return (*lhs.m_value.object) < (*rhs.m_value.object);
6552 return (*lhs.m_value.string) < (*rhs.m_value.string);
6555 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
6558 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
6561 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
6564 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
6567 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
6576 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
6580 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
6584 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
6588 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
6592 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
6596 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
6609 template<
typename ScalarType,
typename std::enable_if<
6610 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6620 template<
typename ScalarType,
typename std::enable_if<
6621 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6648 return !(rhs < lhs);
6655 template<
typename ScalarType,
typename std::enable_if<
6656 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6666 template<
typename ScalarType,
typename std::enable_if<
6667 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6694 return !(lhs <= rhs);
6701 template<
typename ScalarType,
typename std::enable_if<
6702 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6712 template<
typename ScalarType,
typename std::enable_if<
6713 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6740 return !(lhs < rhs);
6747 template<
typename ScalarType,
typename std::enable_if<
6748 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6758 template<
typename ScalarType,
typename std::enable_if<
6759 std::is_scalar<ScalarType>::value,
int>
::type = 0>
6808 const bool pretty_print = o.width() > 0;
6809 const auto indentation = pretty_print ? o.width() : 0;
6816 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
6828 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
6829 friend std::ostream& operator>>(const
basic_json& j, std::ostream& o)
6895 template<
typename InputType>
6896 JSON_HEDLEY_WARN_UNUSED_RESULT
6899 const bool allow_exceptions =
true,
6900 const bool ignore_comments =
false)
6903 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
6933 template<
typename IteratorType>
6934 JSON_HEDLEY_WARN_UNUSED_RESULT
6938 const bool allow_exceptions =
true,
6939 const bool ignore_comments =
false)
6942 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
6946 JSON_HEDLEY_WARN_UNUSED_RESULT
6947 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
parse(ptr, ptr + len))
6950 const bool allow_exceptions =
true,
6951 const bool ignore_comments =
false)
6954 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
6988 template<
typename InputType>
6990 const bool ignore_comments =
false)
6992 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
6995 template<
typename IteratorType>
6996 static bool accept(IteratorType first, IteratorType last,
6997 const bool ignore_comments =
false)
6999 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
7002 JSON_HEDLEY_WARN_UNUSED_RESULT
7003 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
accept(ptr, ptr + len))
7004 static bool accept(detail::span_input_adapter&& i,
7005 const bool ignore_comments =
false)
7007 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
7050 template <
typename InputType,
typename SAX>
7051 JSON_HEDLEY_NON_NULL(2)
7054 const
bool strict = true,
7055 const
bool ignore_comments = false)
7057 auto ia = detail::input_adapter(std::forward<InputType>(i));
7058 return format == input_format_t::json
7059 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
7063 template<
class IteratorType,
class SAX>
7064 JSON_HEDLEY_NON_NULL(3)
7065 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
7066 input_format_t format = input_format_t::
json,
7067 const
bool strict = true,
7068 const
bool ignore_comments = false)
7070 auto ia = detail::input_adapter(std::move(first), std::move(last));
7071 return format == input_format_t::json
7072 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
7076 template <
typename SAX>
7077 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
sax_parse(ptr, ptr + len, ...))
7078 JSON_HEDLEY_NON_NULL(2)
7079 static
bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
7080 input_format_t format = input_format_t::
json,
7081 const
bool strict = true,
7082 const
bool ignore_comments = false)
7085 return format == input_format_t::json
7087 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
7089 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
7100 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
7133 parser(detail::input_adapter(i)).parse(
false, j);
7174 JSON_HEDLEY_RETURNS_NON_NULL
7204 JSON_PRIVATE_UNLESS_TESTED:
7215 #if JSON_DIAGNOSTICS
7328 std::vector<std::uint8_t> result;
7335 binary_writer<std::uint8_t>(o).write_cbor(j);
7340 binary_writer<char>(o).write_cbor(j);
7423 std::vector<std::uint8_t> result;
7430 binary_writer<std::uint8_t>(o).write_msgpack(j);
7435 binary_writer<char>(o).write_msgpack(j);
7525 const bool use_size =
false,
7526 const bool use_type =
false)
7528 std::vector<std::uint8_t> result;
7529 to_ubjson(j, result, use_size, use_type);
7534 const bool use_size =
false,
const bool use_type =
false)
7536 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
7540 const bool use_size =
false,
const bool use_type =
false)
7542 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
7604 std::vector<std::uint8_t> result;
7733 template<
typename InputType>
7734 JSON_HEDLEY_WARN_UNUSED_RESULT
7736 const bool strict =
true,
7737 const bool allow_exceptions =
true,
7742 auto ia = detail::input_adapter(std::forward<InputType>(i));
7750 template<
typename IteratorType>
7751 JSON_HEDLEY_WARN_UNUSED_RESULT
7753 const bool strict =
true,
7754 const bool allow_exceptions =
true,
7759 auto ia = detail::input_adapter(std::move(first), std::move(last));
7764 template<
typename T>
7765 JSON_HEDLEY_WARN_UNUSED_RESULT
7766 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
7768 const bool strict =
true,
7769 const bool allow_exceptions =
true,
7772 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
7776 JSON_HEDLEY_WARN_UNUSED_RESULT
7777 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
7779 const bool strict =
true,
7780 const bool allow_exceptions =
true,
7784 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
7787 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
7877 template<
typename InputType>
7878 JSON_HEDLEY_WARN_UNUSED_RESULT
7880 const bool strict =
true,
7881 const bool allow_exceptions =
true)
7885 auto ia = detail::input_adapter(std::forward<InputType>(i));
7893 template<
typename IteratorType>
7894 JSON_HEDLEY_WARN_UNUSED_RESULT
7896 const bool strict =
true,
7897 const bool allow_exceptions =
true)
7901 auto ia = detail::input_adapter(std::move(first), std::move(last));
7907 template<
typename T>
7908 JSON_HEDLEY_WARN_UNUSED_RESULT
7909 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
7911 const bool strict =
true,
7912 const bool allow_exceptions =
true)
7914 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
7917 JSON_HEDLEY_WARN_UNUSED_RESULT
7918 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
7920 const bool strict =
true,
7921 const bool allow_exceptions =
true)
7924 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
7927 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
7994 template<
typename InputType>
7995 JSON_HEDLEY_WARN_UNUSED_RESULT
7997 const bool strict =
true,
7998 const bool allow_exceptions =
true)
8002 auto ia = detail::input_adapter(std::forward<InputType>(i));
8010 template<
typename IteratorType>
8011 JSON_HEDLEY_WARN_UNUSED_RESULT
8013 const bool strict =
true,
8014 const bool allow_exceptions =
true)
8018 auto ia = detail::input_adapter(std::move(first), std::move(last));
8023 template<
typename T>
8024 JSON_HEDLEY_WARN_UNUSED_RESULT
8025 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
8027 const bool strict =
true,
8028 const bool allow_exceptions =
true)
8030 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
8033 JSON_HEDLEY_WARN_UNUSED_RESULT
8034 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
8036 const bool strict =
true,
8037 const bool allow_exceptions =
true)
8040 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
8043 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
8108 template<
typename InputType>
8109 JSON_HEDLEY_WARN_UNUSED_RESULT
8111 const bool strict =
true,
8112 const bool allow_exceptions =
true)
8116 auto ia = detail::input_adapter(std::forward<InputType>(i));
8124 template<
typename IteratorType>
8125 JSON_HEDLEY_WARN_UNUSED_RESULT
8127 const bool strict =
true,
8128 const bool allow_exceptions =
true)
8132 auto ia = detail::input_adapter(std::move(first), std::move(last));
8137 template<
typename T>
8138 JSON_HEDLEY_WARN_UNUSED_RESULT
8139 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
8141 const bool strict =
true,
8142 const bool allow_exceptions =
true)
8144 return from_bson(ptr, ptr + len, strict, allow_exceptions);
8147 JSON_HEDLEY_WARN_UNUSED_RESULT
8148 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
8150 const bool strict =
true,
8151 const bool allow_exceptions =
true)
8154 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
8157 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
8204 return ptr.get_unchecked(
this);
8232 return ptr.get_unchecked(
this);
8275 return ptr.get_checked(
this);
8318 return ptr.get_checked(
this);
8346 json_pointer::flatten(
"", *
this, result);
8382 return json_pointer::unflatten(*
this);
8447 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
8449 const auto get_op = [](
const std::string & op)
8453 return patch_operations::add;
8457 return patch_operations::remove;
8459 if (op ==
"replace")
8461 return patch_operations::replace;
8465 return patch_operations::move;
8469 return patch_operations::copy;
8473 return patch_operations::test;
8476 return patch_operations::invalid;
8491 if (top_pointer != ptr)
8493 result.
at(top_pointer);
8497 const auto last_path = ptr.
back();
8501 switch (parent.m_type)
8507 parent[last_path] = val;
8513 if (last_path ==
"-")
8520 const auto idx = json_pointer::array_index(last_path);
8521 if (JSON_HEDLEY_UNLIKELY(idx > parent.
size()))
8524 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", parent));
8547 const auto operation_remove = [
this, &result](
json_pointer & ptr)
8550 const auto last_path = ptr.
back();
8558 auto it = parent.
find(last_path);
8559 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
8565 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found", *
this));
8571 parent.
erase(json_pointer::array_index(last_path));
8576 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
8578 JSON_THROW(
parse_error::create(104, 0,
"JSON patch must be an array of objects", json_patch));
8582 for (
const auto& val : json_patch)
8585 const auto get_value = [&val](
const std::string & op,
8586 const std::string & member,
8590 auto it = val.
m_value.object->find(member);
8593 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
8596 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
8599 JSON_THROW(
parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'", val));
8603 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
8606 JSON_THROW(
parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'", val));
8614 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
8620 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
8621 const auto path = get_value(op,
"path",
true).template get<std::string>();
8626 case patch_operations::add:
8628 operation_add(ptr, get_value(
"add",
"value",
false));
8632 case patch_operations::remove:
8634 operation_remove(ptr);
8638 case patch_operations::replace:
8641 result.
at(ptr) = get_value(
"replace",
"value",
false);
8645 case patch_operations::move:
8647 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
8657 operation_remove(from_ptr);
8658 operation_add(ptr, v);
8662 case patch_operations::copy:
8664 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
8673 operation_add(ptr, v);
8677 case patch_operations::test:
8679 bool success =
false;
8684 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
8692 if (JSON_HEDLEY_UNLIKELY(!success))
8694 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump(), val));
8700 case patch_operations::invalid:
8746 JSON_HEDLEY_WARN_UNUSED_RESULT
8748 const std::string& path =
"")
8764 {
"op",
"replace"}, {
"path", path}, {
"value", target}
8775 while (i <
source.size() && i < target.
size())
8778 auto temp_diff =
diff(
source[i], target[i], path +
"/" + std::to_string(i));
8779 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
8788 while (i <
source.size())
8795 {
"path", path +
"/" + std::to_string(i)}
8801 while (i < target.
size())
8806 {
"path", path +
"/-"},
8807 {
"value", target[i]}
8818 for (
auto it =
source.cbegin(); it !=
source.cend(); ++it)
8823 if (target.
find(it.key()) != target.
end())
8826 auto temp_diff =
diff(it.value(), target[it.key()], path_key);
8827 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
8834 {
"op",
"remove"}, {
"path", path_key}
8840 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
8848 {
"op",
"add"}, {
"path", path_key},
8849 {
"value", it.value()}
8870 {
"op",
"replace"}, {
"path", path}, {
"value", target}
8938 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
8940 if (it.value().is_null())
8952 *
this = apply_patch;
8968 NLOHMANN_BASIC_JSON_TPL_DECLARATION
9016 #ifndef JSON_HAS_CPP_20
9025 is_nothrow_move_constructible<nlohmann::json>::value&&
9026 is_nothrow_move_assignable<nlohmann::json>::value
9049 JSON_HEDLEY_NON_NULL(1)
9050 inline
nlohmann::
json operator "" _json(const
char* s, std::
size_t n)
9068 JSON_HEDLEY_NON_NULL(1)
9069 inline
nlohmann::
json::json_pointer operator "" _json_pointer(const
char* s, std::
size_t n)
9074 #include <nlohmann/detail/macro_unscope.hpp>
a class to store JSON values
Definition: json.hpp:177
void insert(const_iterator first, const_iterator last)
inserts elements
Definition: json.hpp:5958
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
Definition: json.hpp:1433
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
Definition: json.hpp:4610
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.hpp:4895
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.hpp:8230
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.hpp:8202
friend bool operator==(const_reference lhs, ScalarType rhs) noexcept
comparison: equal
Definition: json.hpp:6444
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:3989
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition: json.hpp:2688
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:711
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.hpp:6362
static bool sax_parse(InputType &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)
generate SAX events
Definition: json.hpp:7052
ReferenceType get_ref()
get a reference value (implicit)
Definition: json.hpp:3352
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
Definition: json.hpp:6897
reference emplace_back(Args &&... args)
add an object to an array
Definition: json.hpp:5644
const_iterator find(KeyT &&key) const
find an element in a JSON object
Definition: json.hpp:4543
basic_json(const value_t v)
create an empty value with a given type
Definition: json.hpp:1474
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)
copy assignment
Definition: json.hpp:2320
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition: json.hpp:5293
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
Definition: json.hpp:8747
value_type & reference
the type of an element reference
Definition: json.hpp:290
void erase(const size_type idx)
remove element from a JSON array given an index
Definition: json.hpp:4473
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.hpp:4924
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition: json.hpp:3635
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
wrapper to access iterator member functions in range-based for
Definition: json.hpp:4988
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition: json.hpp:3584
iterator begin() noexcept
returns an iterator to the first element
Definition: json.hpp:4680
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition: json.hpp:2053
friend bool operator==(ScalarType lhs, const_reference rhs) noexcept
comparison: equal
Definition: json.hpp:6455
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:7524
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition: json.hpp:1916
const_reverse_iterator rend() const noexcept
returns a const reverse iterator to one before the first
Definition: json.hpp:4866
const_iterator cend() const noexcept
returns a const iterator to one past the last element
Definition: json.hpp:4791
reference back()
access the last element
Definition: json.hpp:4159
static bool accept(InputType &&i, const bool ignore_comments=false)
check if the input is valid JSON
Definition: json.hpp:6989
StringType string_t
a type for a string
Definition: json.hpp:613
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:5215
void push_back(const basic_json &val)
add an object to an array
Definition: json.hpp:5488
friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
Definition: json.hpp:6829
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition: json.hpp:354
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition: json.hpp:4061
void update(const_reference j)
updates a JSON object from another object, overwriting existing keys
Definition: json.hpp:6000
std::size_t size_type
a type to represent container sizes
Definition: json.hpp:297
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition: json.hpp:295
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:1813
reference operator[](const typename object_t::key_type &key)
access specified object element
Definition: json.hpp:3782
reference operator+=(basic_json &&val)
add an object to an array
Definition: json.hpp:5478
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition: json.hpp:1608
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition: json.hpp:305
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:8126
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition: json.hpp:303
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:7735
BooleanType boolean_t
a type for a boolean
Definition: json.hpp:639
void push_back(initializer_list_t init)
add an object to an object
Definition: json.hpp:5596
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition: json.hpp:7175
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:2418
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition: json.hpp:4226
static void to_bson(const basic_json &j, detail::output_adapter< std::uint8_t > o)
Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the ...
Definition: json.hpp:7617
friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept
comparison: not equal
Definition: json.hpp:6489
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:8110
constexpr bool is_structured() const noexcept
return whether type is structured
Definition: json.hpp:2529
friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.hpp:6668
const_iterator begin() const noexcept
returns a const iterator to the first element
Definition: json.hpp:4690
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition: json.hpp:5078
friend bool operator<(const_reference lhs, ScalarType rhs) noexcept
comparison: less than
Definition: json.hpp:6611
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:3486
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:1870
reference front()
access the first element
Definition: json.hpp:4115
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition: json.hpp:2502
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition: json.hpp:2660
detail::cbor_tag_handler_t cbor_tag_handler_t
how to treat CBOR tags
Definition: json.hpp:245
void swap(object_t &other)
exchanges the values
Definition: json.hpp:6204
constexpr bool is_object() const noexcept
return whether value is an object
Definition: json.hpp:2710
const_reference front() const
access the first element
Definition: json.hpp:4123
static std::vector< std::uint8_t > to_bson(const basic_json &j)
Serializes the given JSON object j to BSON and returns a vector containing the corresponding BSON-rep...
Definition: json.hpp:7602
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.hpp:2471
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:850
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition: json.hpp:312
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
Definition: json.hpp:6646
bool empty() const noexcept
checks whether the container is empty.
Definition: json.hpp:5135
friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
serialize to stream
Definition: json.hpp:6805
basic_json(const basic_json &other)
copy constructor
Definition: json.hpp:2190
~basic_json() noexcept
destructor
Definition: json.hpp:2354
basic_json(basic_json &&other) noexcept
move constructor
Definition: json.hpp:2282
friend bool operator>(ScalarType lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.hpp:6714
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.hpp:6478
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts elements
Definition: json.hpp:5816
friend bool operator<(ScalarType lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.hpp:6622
json_value m_value
the value of the current element
Definition: json.hpp:7213
void swap(typename binary_t::container_type &other)
exchanges the values
Definition: json.hpp:6284
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:6738
void swap(array_t &other)
exchanges the values
Definition: json.hpp:6171
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition: json.hpp:4858
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:1850
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition: json.hpp:7326
ReferenceType get_ref() const
get a reference value (implicit)
Definition: json.hpp:3365
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts elements
Definition: json.hpp:5864
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition: json.hpp:3248
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition: json.hpp:8316
const_iterator end() const noexcept
returns a const iterator to one past the last element
Definition: json.hpp:4761
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition: json.hpp:8930
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition: json.hpp:3006
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements
Definition: json.hpp:5917
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition: json.hpp:560
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
Definition: json.hpp:6692
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition: json.hpp:4341
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition: json.hpp:2573
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition: json.hpp:5070
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:4751
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 &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition: json.hpp:6108
void clear() noexcept
clears the contents
Definition: json.hpp:5372
friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:6760
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:7895
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition: json.hpp:2776
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition: json.hpp:1960
iterator insert(const_iterator pos, basic_json &&val)
inserts element
Definition: json.hpp:5787
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:8012
reference operator[](size_type idx)
access specified array element
Definition: json.hpp:3681
friend bool operator>(const_reference lhs, ScalarType rhs) noexcept
comparison: greater than
Definition: json.hpp:6703
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the ...
Definition: json.hpp:7625
void update(const_iterator first, const_iterator last)
updates a JSON object from another object, overwriting existing keys
Definition: json.hpp:6054
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition: json.hpp:8273
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:3292
void swap(binary_t &other)
exchanges the values
Definition: json.hpp:6270
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition: json.hpp:308
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition: json.hpp:314
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:7996
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition: json.hpp:239
friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept
comparison: not equal
Definition: json.hpp:6500
const_reverse_iterator rbegin() const noexcept
returns a const reverse iterator to the last element
Definition: json.hpp:4829
binary_t & get_binary()
Definition: json.hpp:3428
void swap(string_t &other)
exchanges the values
Definition: json.hpp:6237
const_reference back() const
access the last element
Definition: json.hpp:4169
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.hpp:6531
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition: json.hpp:7131
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array (without subtype)
Definition: json.hpp:1860
constexpr bool is_string() const noexcept
return whether value is a string
Definition: json.hpp:2754
constexpr bool is_array() const noexcept
return whether value is an array
Definition: json.hpp:2732
iterator insert_iterator(const_iterator pos, Args &&... args)
Helper for insertion of an iterator.
Definition: json.hpp:5726
basic_json flatten() const
return flattened JSON value
Definition: json.hpp:8343
friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept
comparison: greater than or equal
Definition: json.hpp:6749
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:5451
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:7752
size_type count(KeyT &&key) const
returns the number of occurrences of a key in a JSON object
Definition: json.hpp:4577
const binary_t & get_binary() const
Definition: json.hpp:3439
constexpr bool is_number() const noexcept
return whether value is a number
Definition: json.hpp:2603
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition: json.hpp:5694
reference operator+=(initializer_list_t init)
add an object to an object
Definition: json.hpp:5614
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition: json.hpp:2632
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition: json.hpp:247
const_reference operator[](const typename object_t::key_type &key) const
read-only access specified object element
Definition: json.hpp:3831
iterator find(KeyT &&key)
find an element in a JSON object
Definition: json.hpp:4526
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition: json.hpp:1498
const_reference operator[](size_type idx) const
access specified array element
Definition: json.hpp:3744
AllocatorType< basic_json > allocator_type
the allocator type
Definition: json.hpp:300
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition: json.hpp:921
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition: json.hpp:5540
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(IteratorType first, IteratorType last, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a pair of character iterators
Definition: json.hpp:6935
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition: json.hpp:4641
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:7879
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
Definition: json.hpp:8441
string_t value(const typename object_t::key_type &key, const char *default_value) const
overload for a default value of type const char*
Definition: json.hpp:4011
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
Definition: json.hpp:1570
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition: json.hpp:8380
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition: json.hpp:782
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition: json.hpp:5565
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition: json.hpp:7421
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition: json.hpp:4720
friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept
comparison: less than or equal
Definition: json.hpp:6657
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:1732
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition: json.hpp:3533
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:5765
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition: json.hpp:2803
constexpr bool is_null() const noexcept
return whether value is null
Definition: json.hpp:2551
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 &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition: json.hpp:6141
ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > >> object_t
a type for an object
Definition: json.hpp:514
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)
Definition: json.hpp:3207
reference operator+=(const basic_json &val)
add an object to an array
Definition: json.hpp:5514
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition: json.hpp:4438
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition: json.hpp:1987
static allocator_type get_allocator()
returns the allocator associated with the container
Definition: json.hpp:322
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:3019
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition: json.hpp:4821
an internal type for a backed binary type
Definition: byte_container_with_subtype.hpp:25
BinaryType container_type
the type of the underlying container
Definition: byte_container_with_subtype.hpp:28
std::uint64_t subtype_type
the type of the subtype
Definition: byte_container_with_subtype.hpp:30
deserialization of CBOR, MessagePack, and UBJSON values
Definition: binary_reader.hpp:60
bool sax_parse(const input_format_t format, json_sax_t *sax_, const bool strict=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
Definition: binary_reader.hpp:97
serialization to CBOR and MessagePack values
Definition: binary_writer.hpp:29
void write_bson(const BasicJsonType &j)
Definition: binary_writer.hpp:49
general exception of the basic_json class
Definition: exceptions.hpp:50
exception indicating errors with iterators
Definition: exceptions.hpp:273
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition: iter_impl.hpp:40
void set_end() noexcept
set the iterator past the last value
Definition: iter_impl.hpp:230
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition: iter_impl.hpp:67
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: iter_impl.hpp:736
proxy class for the items() function
Definition: iteration_proxy.hpp:122
Definition: json_ref.hpp:14
a template for a reverse iterator class
Definition: json_reverse_iterator.hpp:35
SAX implementation to create a JSON value from SAX events.
Definition: json_sax.hpp:155
exception indicating other library errors
Definition: exceptions.hpp:415
exception indicating access out of the defined range
Definition: exceptions.hpp:376
Definition: output_adapters.hpp:115
exception indicating a parse error
Definition: exceptions.hpp:185
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, const BasicJsonType &context)
create a parse error exception
Definition: exceptions.hpp:197
Definition: primitive_iterator.hpp:22
Definition: serializer.hpp:41
exception indicating executing a member function with a wrong type
Definition: exceptions.hpp:328
JSON Pointer.
Definition: json_pointer.hpp:20
const std::string & back() const
return last reference token
Definition: json_pointer.hpp:271
void pop_back()
remove last reference token
Definition: json_pointer.hpp:247
bool empty() const noexcept
return whether pointer points to the root document
Definition: json_pointer.hpp:318
std::function< struct zip_source *(struct zip *)> source
Source creation for adding files.
Definition: zip.hpp:122
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition: value_t.hpp:67
value_t
the JSON type enumeration
Definition: value_t.hpp:41
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)
cbor_tag_handler_t
how to treat CBOR tags
Definition: binary_reader.hpp:32
@ error
throw a parse_error exception in case of a tag
parse_event_t
Definition: parser.hpp:27
error_handler_t
how to treat decoding errors
Definition: serializer.hpp:33
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition: hash.hpp:34
std::shared_ptr< output_adapter_protocol< CharType > > output_adapter_t
a type to simplify interfaces
Definition: output_adapters.hpp:37
std::string escape(std::string s)
string escaping as described in RFC 6901 (Sect. 4)
Definition: string_escape.hpp:42
input_format_t
the supported input formats
Definition: input_adapters.hpp:26
namespace for Niels Lohmann
Definition: adl_serializer.hpp:12
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:8969
Definition: type_traits.hpp:154
Definition: to_json.hpp:32
Definition: type_traits.hpp:96
an iterator value
Definition: internal_iterator.hpp:16
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: internal_iterator.hpp:20
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: internal_iterator.hpp:18
Definition: type_traits.hpp:42
Definition: type_traits.hpp:451
Definition: type_traits.hpp:167
Definition: detected.hpp:43
Definition: type_traits.hpp:104
Definition: type_traits.hpp:161
Definition: cpp_future.hpp:141
Definition: cpp_future.hpp:140
SAX interface.
Definition: json_sax.hpp:24
std::size_t operator()(const nlohmann::json &j) const
return a hash value for a JSON object
Definition: json.hpp:8992
bool operator()(nlohmann::detail::value_t lhs, nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition: json.hpp:9008