! @param[in] reference_string the reference string to the current value @param[in] value the value to consider @param[in,out] result the result object to insert values to @note Empty objects or arrays are flattened to `null`. */
| 12381 | @note Empty objects or arrays are flattened to `null`. |
| 12382 | */ |
| 12383 | static void flatten(const std::string& reference_string, |
| 12384 | const BasicJsonType& value, |
| 12385 | BasicJsonType& result) |
| 12386 | { |
| 12387 | switch (value.type()) |
| 12388 | { |
| 12389 | case detail::value_t::array: |
| 12390 | { |
| 12391 | if (value.m_value.array->empty()) |
| 12392 | { |
| 12393 | // flatten empty array as null |
| 12394 | result[reference_string] = nullptr; |
| 12395 | } |
| 12396 | else |
| 12397 | { |
| 12398 | // iterate array and use index as reference string |
| 12399 | for (std::size_t i = 0; i < value.m_value.array->size(); ++i) |
| 12400 | { |
| 12401 | flatten(reference_string + "/" + std::to_string(i), |
| 12402 | value.m_value.array->operator[](i), result); |
| 12403 | } |
| 12404 | } |
| 12405 | break; |
| 12406 | } |
| 12407 | |
| 12408 | case detail::value_t::object: |
| 12409 | { |
| 12410 | if (value.m_value.object->empty()) |
| 12411 | { |
| 12412 | // flatten empty object as null |
| 12413 | result[reference_string] = nullptr; |
| 12414 | } |
| 12415 | else |
| 12416 | { |
| 12417 | // iterate object and use keys as reference string |
| 12418 | for (const auto& element : *value.m_value.object) |
| 12419 | { |
| 12420 | flatten(reference_string + "/" + escape(element.first), element.second, result); |
| 12421 | } |
| 12422 | } |
| 12423 | break; |
| 12424 | } |
| 12425 | |
| 12426 | default: |
| 12427 | { |
| 12428 | // add primitive value with its reference string |
| 12429 | result[reference_string] = value; |
| 12430 | break; |
| 12431 | } |
| 12432 | } |
| 12433 | } |
| 12434 | |
| 12435 | /*! |
| 12436 | @param[in] value flattened JSON |
nothing calls this directly
no test coverage detected