! @param[in] value flattened JSON @return unflattened JSON @throw parse_error.109 if array index is not a number @throw type_error.314 if value is not an object @throw type_error.315 if object values are not primitive @throw type_error.313 if value cannot be unflattened */
| 11018 | @throw type_error.313 if value cannot be unflattened |
| 11019 | */ |
| 11020 | static BasicJsonType |
| 11021 | unflatten(const BasicJsonType& value) |
| 11022 | { |
| 11023 | if (JSON_HEDLEY_UNLIKELY(not value.is_object())) |
| 11024 | { |
| 11025 | JSON_THROW(detail::type_error::create(314, "only objects can be unflattened")); |
| 11026 | } |
| 11027 | |
| 11028 | BasicJsonType result; |
| 11029 | |
| 11030 | // iterate the JSON object values |
| 11031 | for (const auto& element : *value.m_value.object) |
| 11032 | { |
| 11033 | if (JSON_HEDLEY_UNLIKELY(not element.second.is_primitive())) |
| 11034 | { |
| 11035 | JSON_THROW(detail::type_error::create(315, "values in object must be primitive")); |
| 11036 | } |
| 11037 | |
| 11038 | // assign value to reference pointed to by JSON pointer; Note that if |
| 11039 | // the JSON pointer is "" (i.e., points to the whole value), function |
| 11040 | // get_and_create returns a reference to result itself. An assignment |
| 11041 | // will then create a primitive value. |
| 11042 | json_pointer(element.first).get_and_create(result) = element.second; |
| 11043 | } |
| 11044 | |
| 11045 | return result; |
| 11046 | } |
| 11047 | |
| 11048 | /*! |
| 11049 | @brief compares two JSON pointers for equality |
nothing calls this directly
no test coverage detected