Hubert-Dudek
Databricks MVP

for sure function (def) should be declared outside loop, move it after importing libraries,

logic is a bit complicated you need to debug it using display(Flatten_df2) (or .show()) and validating json after each iteration (using break or sleep etc.)


My blog: https://databrickster.medium.com/