Problem
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.
Task
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:
- Nested dictionary keys are joined with
. - List indices are written as
[i] - Primitive values (
str,int,float,bool,None) become final entries - Empty dictionaries and empty lists should also be preserved as values at their path
Input / Output
- Input: a Python object composed only of dictionaries, lists, strings, numbers, booleans, and
None - Output: a dictionary mapping flattened path strings to values
Constraints
- The input contains only dictionaries, lists, strings, integers, floats, booleans, and null-like values (
Nonein Python) - Total number of dictionary entries and list elements is in the range
0to10^5 - Maximum nesting depth is in the range
0to10^3 - Dictionary keys are non-empty strings without
.or bracket characters
Function Signature
def flatten_json(data):
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.


