Supposed to be an array structured like this:
[
{
"key_set1": {
int_val: 3,
arr_val: [
1,
3,
4
]
}
},
{
"key_set2": {
string_val: "foo"
}
}
]
I aim to flatten the inner object keys into a new root object, resulting in:
{
"key_set1": {
"int_val": 3,
"arr_val": [
1,
3,
4
]
},
"key_set2": {
"string_val": "foo"
}
}
Considerations:
- The nested structure may have N levels with N > 10
- The structure is valid JSON not Javascript object (atomit/non-atomic types)
- The input json file can be large (hundreds of KBytes)
- Must use JavaScript V8 / ECMAScript6 for processing
- Processing time needs to be within milliseconds
- Variants of this mapping will involve parsing input JSON and modifying values using methods like
map
I seek the most optimized solution utilizing built-in methods such as forEach
, fast iterators for
, while
, etc., for optimal performance in best/worst cases.