! @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`. */
| 9220 | @note Empty objects or arrays are flattened to `null`. |
| 9221 | */ |
| 9222 | static void flatten(const std::string& reference_string, |
| 9223 | const BasicJsonType& value, |
| 9224 | BasicJsonType& result) |
| 9225 | { |
| 9226 | switch (value.m_type) |
| 9227 | { |
| 9228 | case detail::value_t::array: |
| 9229 | { |
| 9230 | if (value.m_value.array->empty()) |
| 9231 | { |
| 9232 | // flatten empty array as null |
| 9233 | result[reference_string] = nullptr; |
| 9234 | } |
| 9235 | else |
| 9236 | { |
| 9237 | // iterate array and use index as reference string |
| 9238 | for (std::size_t i = 0; i < value.m_value.array->size(); ++i) |
| 9239 | { |
| 9240 | flatten(reference_string + "/" + std::to_string(i), |
| 9241 | value.m_value.array->operator[](i), result); |
| 9242 | } |
| 9243 | } |
| 9244 | break; |
| 9245 | } |
| 9246 | |
| 9247 | case detail::value_t::object: |
| 9248 | { |
| 9249 | if (value.m_value.object->empty()) |
| 9250 | { |
| 9251 | // flatten empty object as null |
| 9252 | result[reference_string] = nullptr; |
| 9253 | } |
| 9254 | else |
| 9255 | { |
| 9256 | // iterate object and use keys as reference string |
| 9257 | for (const auto& element : *value.m_value.object) |
| 9258 | { |
| 9259 | flatten(reference_string + "/" + escape(element.first), element.second, result); |
| 9260 | } |
| 9261 | } |
| 9262 | break; |
| 9263 | } |
| 9264 | |
| 9265 | default: |
| 9266 | { |
| 9267 | // add primitive value with its reference string |
| 9268 | result[reference_string] = value; |
| 9269 | break; |
| 9270 | } |
| 9271 | } |
| 9272 | } |
| 9273 | |
| 9274 | /*! |
| 9275 | @param[in] value flattened JSON |
nothing calls this directly
no test coverage detected