I am consuming a data structure from Contentful, which looks like this:
{
sys: {}
fields: {
type: 'page',
children: [
{
sys: {}
fields: {
type: 'section',
children: [
...andSoOn
]
}
}
]
}
}
I want to recursively serialise the data with the following pattern:
const serialise = entry => entry.fields
Basically, I want to flatten out the fields nested object, and remove the sys object.
How can I do this recursively, for any number of nested children?