| 2155 | detail::is_getable<basic_json_t, ValueType>::value |
| 2156 | && !std::is_same<value_t, ValueType>::value, int >::type = 0 > |
| 2157 | ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const |
| 2158 | { |
| 2159 | // at only works for objects |
| 2160 | if (JSON_HEDLEY_LIKELY(is_object())) |
| 2161 | { |
| 2162 | // if key is found, return value and given default value otherwise |
| 2163 | const auto it = find(key); |
| 2164 | if (it != end()) |
| 2165 | { |
| 2166 | return it->template get<ValueType>(); |
| 2167 | } |
| 2168 | |
| 2169 | return default_value; |
| 2170 | } |
| 2171 | |
| 2172 | JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this)); |
| 2173 | } |
| 2174 | |
| 2175 | /// @brief access specified object element with default value |
| 2176 | /// @sa https://json.nlohmann.me/api/basic_json/value/ |