// __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.12.0 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT #pragma once #include // int64_t #include // map #include // basic_string #include // enable_if, is_constructible #include // unordered_map #include // vector #include #include #include #include #include #include NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { namespace view { /// selects a conversion by its target type template struct value_tag {}; /*! @brief the number or boolean of a node converted to an arithmetic type As basic_json's get() for arithmetic types: integers and floats are converted with static_cast, booleans give 0 or 1, and other types throw type_error.302. */ template NLOHMANN_VIEW_ALWAYS_INLINE T arithmetic_value(const document_data& d, const node& n) { switch (static_cast(n.kind)) { case value_t::number_unsigned: return static_cast(static_cast(integer_bits(n))); case value_t::number_integer: return static_cast(static_cast(static_cast(integer_bits(n)))); case value_t::number_float: return static_cast(float_value(d.str(n), n)); case value_t::boolean: return static_cast((n.flags & node_flags::is_true) != 0); case value_t::null: case value_t::object: case value_t::array: case value_t::string: case value_t::binary: case value_t::discarded: default: throw_type_error(302, "type must be number, but is ", value_type_name(static_cast(n.kind))); } } /// std::vector from an array, element by element (type_error.302 otherwise) template std::vector vector_value(const View& v) { if (NLOHMANN_VIEW_UNLIKELY(!v.is_array())) { throw_type_error(302, "type must be array, but is ", v.type_name()); } std::vector r; r.reserve(v.size()); for (const View e : v) { r.push_back(e.template get()); } return r; } /// a map with string keys from an object; with duplicate keys, the last /// value is kept, as parse() does (type_error.302 for other types) template Map map_value(const View& v) { if (NLOHMANN_VIEW_UNLIKELY(!v.is_object())) { throw_type_error(302, "type must be object, but is ", v.type_name()); } Map r; for (auto it = v.begin(); it != v.end(); ++it) { const auto key = it.key(); r[typename Map::key_type(key.data(), key.size())] = it.value().template get(); } return r; } /// whether a map type is read member by member (its keys are made from /// characters and a length); other maps go through basic_json template struct is_string_key : std::is_constructible {}; } // namespace view } // namespace detail NLOHMANN_JSON_NAMESPACE_END