Use python to create a nested json -


{"0":{"posted_date":"25 jun 2015"},"1":{"posted_date":"26 jun 2015"}}

note:

  1. that '0' , '1' variable - 'count', variable generate through repeat/loop
  2. "posted_date" string
  3. "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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -