MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / flatten_

Function flatten_

include/jsoncons_ext/jsonpointer/jsonpointer.hpp:1288–1349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1286
1287 template <typename Json>
1288 void flatten_(const std::basic_string<typename Json::char_type>& parent_key,
1289 const Json& parent_value,
1290 Json& result)
1291 {
1292 using char_type = typename Json::char_type;
1293 using string_type = std::basic_string<char_type>;
1294
1295 switch (parent_value.type())
1296 {
1297 case json_type::array:
1298 {
1299 if (parent_value.empty())
1300 {
1301 // Flatten empty array to null
1302 //result.try_emplace(parent_key, null_type{});
1303 //result[parent_key] = parent_value;
1304 result.try_emplace(parent_key, parent_value);
1305 }
1306 else
1307 {
1308 for (std::size_t i = 0; i < parent_value.size(); ++i)
1309 {
1310 string_type key(parent_key);
1311 key.push_back('/');
1312 jsoncons::from_integer(i,key);
1313 flatten_(key, parent_value.at(i), result);
1314 }
1315 }
1316 break;
1317 }
1318
1319 case json_type::object:
1320 {
1321 if (parent_value.empty())
1322 {
1323 // Flatten empty object to null
1324 //result.try_emplace(parent_key, null_type{});
1325 //result[parent_key] = parent_value;
1326 result.try_emplace(parent_key, parent_value);
1327 }
1328 else
1329 {
1330 for (const auto& item : parent_value.object_range())
1331 {
1332 string_type key(parent_key);
1333 key.push_back('/');
1334 escape(jsoncons::basic_string_view<char_type>(item.key().data(),item.key().size()), key);
1335 flatten_(key, item.value(), result);
1336 }
1337 }
1338 break;
1339 }
1340
1341 default:
1342 {
1343 // add primitive parent_value with its reference string
1344 //result[parent_key] = parent_value;
1345 result.try_emplace(parent_key, parent_value);

Callers 1

flattenFunction · 0.70

Calls 11

from_integerFunction · 0.85
escapeFunction · 0.85
typeMethod · 0.80
atMethod · 0.80
emptyMethod · 0.45
try_emplaceMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45
keyMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected