python dict to json example


sample = {'Example1': 111, 'Example2': 222, 'Examples3': 3333}

print json.dumps([{'name': k, 'size': v} for k,v in sample.items()], indent=4)

[
{
"name": "Example2",
"size": 222
},
{
"name": "Examples3",
"size": 3333
},
{
"name": "Example1",
"size": 111
}
]

Leave a Reply

Your email address will not be published. Required fields are marked *