>>> import json
>>> url_list = ['http://www.google.com', 'http://www.yahoo.com']
>>> json.dumps({'entry': [{'url': v} for v in url_list]})
'{"entry": [{"url": "http://www.google.com"}, {"url": "http://www.yahoo.com"}]}'
>>> print json.dumps({'entry': [{'url': v} for v in url_list]}, indent=4)
{
"entry": [
{
"url": "http://www.google.com"
},
{
"url": "http://www.yahoo.com"
}
]
}
The amount of whitespace isn’t significant in json. If you want a fancy format, you’ll have to do some work yourself
solved how do I convert array to JSON