Use python to create a nested json -
{"0":{"posted_date":"25 jun 2015"},"1":{"posted_date":"26 jun 2015"}}
note:
- that '0' , '1' variable - 'count', variable generate through repeat/loop
- "posted_date" string
- "25 jun 2015" , "26 jun 2015" variable - 'date'
how create json output above python?
[edit-not working code]
import json final = [] count = 0 postid = 224 while postid < 1200: final.append({count: {"posted_id":postid}}) count = count + 1 postid = postid * 2 print str(json.dumps(final))
import json dates = ["25 jun 2015", "26 jun 2015", "27 jun 2015"] result = {} each, date in enumerate(dates): result.update({each: {"posted_data": date}}) jsoned = json.dumps(result)
you don't need use "count" variable
Comments
Post a Comment