An interesting challenge with opportunities to delve into mixed blood Spanish-royal lineages, with a pinch of nested json.
The input is a nested JSON file that looks like the one below, and the desired output is a wide table with clean attributes.
My full solution contains the final code in the form of a dbt docs page, but the TLDR is that I followed a three layer approach:
The first model runs consecutive lateral flatten on house and monarch, the second (aux) model retrieves the unique list of keys (attributes), and the third one loops over the list of keys and creates the wide table.
First model:
And the output:
Thanks for reading!
Find this and other FrostyFriday challenges with dbt in my repo .