Open
Description
Hi I want to keep parent key and all its children as stringified JSON, is it possible to do that with flatten?
Example
{
a : 'blah',
data : {
a : 'sth',
b: 'sth'
}
}
expected output
{
a: 'blah',
data: `{
a: sth,
b: sth
}`,
data.a = sth,
data.b = sth
}
I really appreciate if you can guide me here? Thanks
Reacted by George Eracleous
Metadata
Metadata
Assignees
Labels
No labels
Activity
yashinnhl commentedon Nov 5, 2020
We can add key and value when isObject is true.
giorgosera commentedon Nov 13, 2020
Hey @yashinnhl ! I'm also interested in this.
I'm not sure I understood your second comment! What do you mean by dictionary?
yashinnhl commentedon Dec 2, 2020
Hey @giorgosera I edited my comments. Sorry for confusion. In general, I mean we can keep first level keys just like an example even if they are object.
consider this :
Can be converted to :
To achieve this, we need to add condition - if (isObject) - to the index, and output[newKey] = value will keep parent key for us.
For example, value = { a: sth, b: sth } will be assigned data key first and then flatten process will create
data.a = sth, and data.b = sth.I hope it helps. I am still not sure it is optimized or not but at least worked for me :).