Write a function to transform a complex JSON structure into a flattened relational format.
Implement flatten_json(data), where data is a JSON object containing nested objects and arrays. Return a list of dictionaries with dotted keys. Arrays of objects must produce one output row per object, repeating parent fields; multiple nested arrays expand as a Cartesian product. Arrays of primitive values remain unchanged in their flattened field.
Example: {"id": 1, "items": [{"sku": "A"}, {"sku": "B"}]} becomes [{"id": 1, "items.sku": "A"}, {"id": 1, "items.sku": "B"}]. Preserve input order and do not mutate the input.
def flatten_json(data):