Walmart Global Tech frontend services often transform nested catalog and fulfillment data before rendering it. Implement flatten_data to convert a nested JSON-like object or array into a single dictionary whose keys represent each value's path.
The input is a non-empty JSON-like dictionary or list. Dictionary keys contain no periods. Values may be dictionaries, lists, strings, numbers, booleans, or None.
Use dot notation for dictionary keys and zero-based numeric components for list indices. Each scalar value becomes an entry in the output dictionary. Preserve empty dictionaries and lists as values at their own path. For a root scalar, the path is the empty string, although root scalars are excluded by the constraints.
For example, {"item": {"sku": "A1"}} becomes {"item.sku": "A1"}, while {"items": [{"id": 7}]} becomes {"items.0.id": 7}.
def flatten_data(data):