Flatten JSON
Start Timer
0:00:00
Given a JSON
string with nested objects, write a function flatten_json
that flattens all the objects to a single key-value dictionary. Do not use the library that actually performs this function.
Example:
Input:
import json
json_str = json.dumps({'a':{'b':'c', 'd':'e'}})
Output:
def flatten_json(json_str) -> json.dumps({'a_b':'c', 'a_d':'e'})
Note: Input and output are in string
format : use json.dumps()
to convert python dictionary to string.
Recommended questions for you
Personalized based on your user activity, skill level, and preferences.
.
.
.
.
.
.
.
.
.
Comments