At Meta, event payloads from products like Facebook and Instagram may contain deeply nested JSON structures. Write a Python function that flattens a nested JSON-like object into a single dictionary of path-value pairs.
Given a Python object data representing parsed JSON, return a flat dictionary where each key is the full path to a primitive value.
Use these rules:
.[i]str, int, float, bool, None) become final entriesNoneExample 1
Input: {"user": {"id": 7, "profile": {"name": "Ana"}}, "active": true}
Output: {"user.id": 7, "user.profile.name": "Ana", "active": true}
Explanation: Nested object keys are joined with . until a primitive value is reached.
Example 2
Input: {"posts": [{"id": 1}, {"id": 2, "tags": ["ml", "meta"]}]}
Output: {"posts[0].id": 1, "posts[1].id": 2, "posts[1].tags[0]": "ml", "posts[1].tags[1]": "meta"}
Explanation: List positions are included in the path using bracket notation.
0 and 10^50 and 10^3. or bracket characters