Flatten JSON
Write flatten_json(obj) that turns nested dicts and into a single-level dict whose keys are dotted paths. List elements use their index as a key segment. Scalars keep their values.
Examples
flatten_json({"a": {"b": 1, "c": [10, 20]}, "d": "x"}) → {"a.b": 1, "a.c.0": 10, "a.c.1": 20, "d": "x"}Exercise
4 checksFlatten JSON
def flatten_json(obj):
...
print(flatten_json({"a": {"b": 1, "c": [10, 20]}, "d": "x"}))
Press Run to try your code, then Check answer to grade it.