DataArt data-engineering pipelines often receive nested JSON payloads that must be converted into records for downstream processing. Write a function that flattens a nested JSON object into a list of row objects.
Implement flatten_json(data), where data is a JSON object represented by a Python dictionary. Return a list of Python dictionaries. Nested object keys must be joined with . to form column names. Arrays of objects must be expanded into separate rows. If multiple arrays of objects occur at the same level, produce the Cartesian product of their elements. Arrays of scalar values remain unchanged under their flattened key.
The input root is always an object. Object key order does not affect correctness. An empty array is preserved as an empty array value, and an empty object contributes no columns.
def flatten_json(data):