! @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 */
| 12443 | @throw type_error.313 if value cannot be unflattened |
| 12444 | */ |
| 12445 | static BasicJsonType |
| 12446 | unflatten(const BasicJsonType& value) |
| 12447 | { |
| 12448 | if (JSON_HEDLEY_UNLIKELY(!value.is_object())) |
| 12449 | { |
| 12450 | JSON_THROW(detail::type_error::create(314, "only objects can be unflattened")); |
| 12451 | } |
| 12452 | |
| 12453 | BasicJsonType result; |
| 12454 | |
| 12455 | // iterate the JSON object values |
| 12456 | for (const auto& element : *value.m_value.object) |
| 12457 | { |
| 12458 | if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive())) |
| 12459 | { |
| 12460 | JSON_THROW(detail::type_error::create(315, "values in object must be primitive")); |
| 12461 | } |
| 12462 | |
| 12463 | // assign value to reference pointed to by JSON pointer; Note that if |
| 12464 | // the JSON pointer is "" (i.e., points to the whole value), function |
| 12465 | // get_and_create returns a reference to result itself. An assignment |
| 12466 | // will then create a primitive value. |
| 12467 | json_pointer(element.first).get_and_create(result) = element.second; |
| 12468 | } |
| 12469 | |
| 12470 | return result; |
| 12471 | } |
| 12472 | |
| 12473 | /*! |
| 12474 | @brief compares two JSON pointers for equality |
nothing calls this directly
no test coverage detected