how to convert dict to json in Python

PHOTO EMBED

Wed Jun 19 2024 08:27:37 GMT+0000 (Coordinated Universal Time)

Saved by @freepythoncode ##python #coding #python #programming #json

import pandas as pd

# All arrays must be of the same length
dict_data = {
    'users': [{'name': 'test'}, {'name': '123'}], 
    'tasks': [{'name': 'test123'}, {'name': '45456'}]
}

df = pd.DataFrame.from_dict(dict_data)
df.to_json('out.json', indent = 4)
content_copyCOPY