This is an Apps Script version of the code referred to in Flattening arrays for Elastic Search. The point of that article is to prepare data arriving from GraphQL for elastic search, but it also solves the problem of taking highly nested data with arrays that need to be explored and arranging it for rendering in a sheet.
Lets’ start with this data.
To be able to render this in a sheet, the arrays need to be blown out, and the parent data repeated on each row – like this.

That’s a little more complex than simple object flattening, as we need to create a duplicate row each time there is an array element, and of course, these arrays might occur at any level.

The code

The Es6 version of this can be found at Flattening arrays for Elastic Search, but it needs a downgrade for Apps Script. The code can also be included in your Script from my cUseful library – library key 1EbLSESpiGkI3PYmJqWh3-rmLkYKAtCNPi1L2YCtMgo2Ut8xMThfJ41Ex or on Github
Which gives this result, with the header row in the first element

Putting it together

Assuming the JSON data earlier in the article is in a variable called films, here’s the whole thing, using the cUseful library.
Since G+ is closed, you can now star and follow post announcements and discussions on Github, here